How to save matrix to .dat file in standard notation

38 次查看(过去 30 天)
Hi!
I would like to save a binary matrix 'A' to the file 'output.dat' without scientific notation formatting. For instance the matrix A has the (1,1) element, A(1,1) = 0. But it is saved as 0.0000000..e+00, when I'd simply like to to be saved as just 0.
I'm currently using the following basic save function,
A = [0 1 1 0; 0 0 0 1; 1 0 1 0; 0 0 0 0] % Example binary matrix A
save(['output=' num2str(i+1) '.dat'],'A','-ascii');
any help would be greatly appreciated.
Thank you!

采纳的回答

Walter Roberson
Walter Roberson 2019-4-22
You cannot do that using save -ascii: save -ascii uses a fixed format.
Probably the easest way is
filename = sprintf('output=%d.dat', i+1);
dlmwrite(filename, A, ' ' )

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by