How to save matrix to .dat file in standard notation

28 vues (au cours des 30 derniers jours)
Dipie11
Dipie11 le 22 Avr 2019
Commenté : Dipie11 le 22 Avr 2019
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!

Réponse acceptée

Walter Roberson
Walter Roberson le 22 Avr 2019
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, ' ' )
  1 commentaire
Dipie11
Dipie11 le 22 Avr 2019
Awesome, thank you for your help!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by