Display of data side by side

조회 수: 4 (최근 30일)
raghavendra kandukuri
raghavendra kandukuri 2018년 8월 21일
댓글: raghavendra kandukuri 2018년 8월 22일
Hi,
I have an output in txt file(notepad) which is displaying all in a single row, instead I want them side by side, following is the code I am using right now:
x1='TORQUE:';
dlmwrite('LTM.txt',x1,'delimiter','','-append','newline','pc');
dlmwrite('LTM.txt',Yout,'-append','newline','pc');
y1='ENGINE SPEED:';
dlmwrite('LTM.txt',y1,'delimiter','','-append','newline','pc');
dlmwrite('LTM.txt',temp2,'-append','newline','pc');
z1='DURATION:';
dlmwrite('LTM.txt',z1,'delimiter','','-append','newline','pc');
dlmwrite('LTM.txt',temp3,'-append','newline','pc');
dlmwrite('LTM.txt',Yout,'delimiter','\t');
Attached is the output file

채택된 답변

Walter Roberson
Walter Roberson 2018년 8월 21일
dlmwrite() adds the line terminator at the end of the last line that you write. When you -append on the next call, it appends to the end -- which is to say after that line terminator.
dlmwrite() cannot be used to append columns to an existing text file. Not even if you use the range inputs: the range input creates a zero-padded matrix and writes or appends that.
You will probably need to use fopen()/fprintf()/fclose() to get the file you want.
  댓글 수: 2
raghavendra kandukuri
raghavendra kandukuri 2018년 8월 22일
Thank you Walter, this one works.
abc=[Yout,temp2]
fileID = fopen('LTM.txt','w');
fprintf(fileID,'%3s %12s %12s\r\n','Torque','EngineSpeed','Duration');
fprintf(fileID,'%6.2f %12.2f\r\n',transpose(abc));
fclose(fileID);
raghavendra kandukuri
raghavendra kandukuri 2018년 8월 22일
https://www.mathworks.com/matlabcentral/answers/63621-writing-a-table-into-a-text-file#answer_75217

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by