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

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

问题描述

我将矩阵保存到这样的文件中:

I save a matrix to a file like this:

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

有没有办法告诉 MATLAB 写 0 而不是 0.0000000e+000 值?这会很好,因为它会更快更容易地查看哪些值不同于零.

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.

推荐答案

我建议使用 DLMWRITE 而不是 SAVE 因为你正在处理ASCII 文件.它可以让您更好地控制格式.例如,您可以创建一个由空格分隔的输出文件,其字段宽度为 10 位和小数点后 6 位(请参阅有关格式说明符的更多信息 这里):

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天全站免登陆