Writing a table into a text file
7 次查看(过去 30 天)
显示 更早的评论
Hi
I am getting so dizzy, i wrote a code and i want to record a table named 'DI' into a text file. I follow the instructions that is given here http://www.mathworks.com/help/matlab/ref/fprintf.html , but unfortunately it writes something quite different from the original table. I doubted that the code is wrong so i used the example that is given in the above link in my code and it gives me totally right answers.
The code that i use for this text writing is
fileID=fopen('ParkAngDI11.txt','w+');
fprintf(fileID,'%6s %12s\r\n','Time','Damage Index');
fprintf(fileID,'%6.2f %12.8f\r\n',DI);
fclose(fileID);
I would be so thankful if you help me through this.
2 个评论
采纳的回答
per isakson
2013-2-15
编辑:per isakson
2013-2-15
My guess: column-wise. Change
fprintf(fileID,'%6.2f %12.8f\r\n',DI);
to
fprintf(fileID,'%6.2f %12.8f\r\n',transpose(DI));
2 个评论
per isakson
2013-2-16
编辑:per isakson
2013-2-16
Column-wise is the key to understand why. fprintf reads column-wise from the input matrix and writes "row-wise" to the file controlled by the format specification. Remember: Matlab is "column-first-oriented". Try
clc
M = [ 11, 12; 21, 22 ]
disp('-- fprintf --')
fprintf( 1, '%4d,%4d\n', M )
result in the command window
M =
11 12
21 22
-- fprintf --
11, 21
12, 22
>>
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!