将矩阵保存到文件时,如何控制格式? [英] How can I control the formatting when saving a matrix to a file?

查看:154
本文介绍了将矩阵保存到文件时,如何控制格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我保存一个矩阵到这样的文件:

$ $ p $ save(filepath,'mtrx','-ascii') ;

有没有办法告诉MATLAB写 0 而不是 0.0000000e + 000 值?这将是很好的,因为它会更快,更容易看到哪些值不等于零。我建议使用 DLMWRITE 而不是 SAVE ,因为你正在处理ASCII文件。它会给你更多的格式控制。例如,您可以创建一个由小数点后的字段宽度为10和6位的空格分隔的输出文件(有关格式说明符的更多信息,请参见):

  dlmwrite(filepath,mtrx,'ref / fprintf.htmlrel =noreferrer> here )分隔符','','精度','%10.6g'); 


I save a matrix to a file like this:

save(filepath, 'mtrx', '-ascii');

Is there a way to tell MATLAB to write 0 instead of 0.0000000e+000 values? It would be nice because it would be faster and easier to see which values differ from zero.

解决方案

I suggest using DLMWRITE instead of SAVE since you're dealing with ASCII files. It will give you more control over the formatting. For example, you could create an output file delimited by spaces with a field width of 10 and 6 digits after the decimal point (see more about format specifiers here):

dlmwrite(filepath,mtrx,'delimiter',' ','precision','%10.6g');

这篇关于将矩阵保存到文件时,如何控制格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆