How can I control the formatting when saving a matrix to a file?

╄→尐↘猪︶ㄣ 提交于 2019-12-30 10:47:11

问题


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.


回答1:


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');


来源:https://stackoverflow.com/questions/6127037/how-can-i-control-the-formatting-when-saving-a-matrix-to-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!