How can I control the formatting when saving a mat

2019-02-18 15:59发布

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条回答
够拽才男人
2楼-- · 2019-02-18 16:25

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');
查看更多
登录 后发表回答