Save data to file
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
monkey_matlab
am 27 Okt. 2015
Beantwortet: Star Strider
am 27 Okt. 2015
Hello,
In my code below, I am having a problem saving the matrix A properly to a file. The saved data is getting mixed up and does not correspond to the matrix A. Can you help me save the data properly?
a = (0.5)*rand(20,1);
b = (0.5)*rand(20,1);
c = (0.5)*rand(20,1);
d = (0.5)*rand(20,1);
e = (0.5)*rand(20,1);
A = [a b c d e];
fileID = fopen('check.txt','w');
fprintf(fileID,'%6s %6s %6s %6s %6s\r\n','a','b', 'c', 'd', 'e');
fprintf(fileID,'%6.5f %6.5f %6.5f %6.5f %6.5f\r\n',A);
fclose(fileID);
0 Kommentare
Akzeptierte Antwort
Star Strider
am 27 Okt. 2015
Transpose ‘A’ and it should work:
fprintf(fileID,'%6.5f %6.5f %6.5f %6.5f %6.5f\r\n',A.');
or if ‘A’ will always be real:
fprintf(fileID,'%6.5f %6.5f %6.5f %6.5f %6.5f\r\n',A');
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Argument Definitions finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!