필터 지우기
필터 지우기

how to store variables in coloum in text file?

조회 수: 5 (최근 30일)
SHARAD KUMAR UPADHYAY
SHARAD KUMAR UPADHYAY 2019년 5월 26일
댓글: SHARAD KUMAR UPADHYAY 2019년 5월 29일
With respect sir,
%I want to stored my output variables in .txt file in coloum wise. i am using this comaand to save
save('filename.txt','variable1','variable2',etc..)
%but i got the output in rows, so please tell me how can i save my variables in coulomn?
% I save my variable in .mat file that is also saved in rows
save('filename.mat','variable1','variable2',etc..)
% Can I save output variable in both .mat and .txt format by using one line command in coulomn

답변 (1개)

darova
darova 2019년 5월 26일
I'd use fprintf():
f = fopen('plot.txt', 'wt'); % 'wt' - write file, text mode
formspec = '%f %f\n'; % two values in a row (\n - line break)
% formspec = '%f %f %f\n'; % tree values in a row
for i = 1:3
a = rand;
b = rand;
fprintf(f, formspec, a,b);
end
fclose(f);
read about fprintf(), formatSpec. Look also for dlmwrite()
  댓글 수: 3
darova
darova 2019년 5월 29일
Just remove '\n' (line break)
fprintf(fileID,'%6.2e %12.8e ',output,T);
SHARAD KUMAR UPADHYAY
SHARAD KUMAR UPADHYAY 2019년 5월 29일
I found the all values of output and T in a single rwo. I want all values of output in one coulom and of T in second one.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by