How to save this matrix?

1 Ansicht (letzte 30 Tage)
Amanda Queiroz
Amanda Queiroz am 24 Dez. 2021
Bearbeitet: Amanda Queiroz am 28 Dez. 2021
I have 12 columns in matrix:
For example:
6,2713 1,0876 23,3585 31,5388 51,1182 27,1688 9,6255 0,7503 0 0 0 0,3299 -5,8128 -37,5098
6,0273 1,0467 22,9448 31,1567 48,5899 26,2585 9,6405 0,7245 0 0 0 0,3299 -5,8173 -37,5098
5,6551 0,9194 22,7827 29,8986 47,5964 24,7148 9,7817 0,6674 0 0 0 0,3299 -5,8217 -37,5098
How to save this matrix with fprintf for txt file?
I tried
fileID = fopen('test.txt','w');
fprintf(fileID,'%.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\n',[a,b,c,d,e,f,g,h,i,j,k,l,m,n];

Akzeptierte Antwort

dpb
dpb am 24 Dez. 2021
If there's just one array/matrix M, then
fid=fopen('test.txt','w');
fmt=[repmat('%.4f',1,size(M,2)) '\n']; % build format string
fprintf(fid,fmt,M.') % write -- NB: to transpose
fid=fclose(fid);
But, I'd recommend using one of the higher-level routines instead of the low-level i/o unless the desired file format is one that can't be written otherwise. See
doc writematrix
and friends...
  1 Kommentar
Amanda Queiroz
Amanda Queiroz am 27 Dez. 2021
Bearbeitet: Amanda Queiroz am 28 Dez. 2021
Thank you, these commands got it right!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by