필터 지우기
필터 지우기

Writing a table into a text file

조회 수: 10 (최근 30일)
Arman Kam
Arman Kam 2013년 2월 15일
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
Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 15일
What this table is containing?
Arman Kam
Arman Kam 2013년 2월 16일
The Table contains somee numbersd that is irrelevant with the original table that exists in matlab.
some the datas from original table is
0.0100000000000000 0
0.0200000000000000 0
0.0300000000000000 0
0.0400000000000000 0
0.0500000000000000 0
0.0600000000000000 0
0.0700000000000000 0
0.0800000000000000 0
0.0900000000000000 0
0.100000000000000 0
and it the first column continues to 39.98 and second column takes some values corresponding to column one.
the data that matlab writes for me is
Time Damage Index
0.01 0.02000000
0.03 0.04000000
0.05 0.06000000
0.07 0.08000000
0.09 0.10000000
0.11 0.12000000
0.13 0.14000000
0.15 0.16000000
.
.
.
39.91 39.92000000
39.93 39.94000000
39.95 39.96000000
39.97 39.98000000
0.00 0.00000000
0.00 0.00000000
.
.
.
0.00 0.00000000
0.00 0.00000000
0.00 0.00000000
0.00 0.00000000
-0.12 -0.12093101
-0.12 -0.12093101
-0.12 -0.12093101
-0.12 -0.12093101
i really need to write these tables to text file but i don't know what is wrong!!!

댓글을 달려면 로그인하십시오.

채택된 답변

per isakson
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
Arman Kam
Arman Kam 2013년 2월 16일
Thank you so much dear Per Isakson your solution worked, Can you tell me why is this happening?!
per isakson
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by