필터 지우기
필터 지우기

How can I sava a series of variables to a txt file?

조회 수: 1 (최근 30일)
Marty Dutch
Marty Dutch 2013년 9월 27일
댓글: Marty Dutch 2013년 10월 1일
Hi all,
I have a huge series of variables in the matlab workspace. Below you'll find an example of how one of these variables looks like. The problem comes when I want to save all of them to a single textfile. The code below works, although I know there must be a more elegant and faster way to do is. Note that some variables are missing (data3, data5 and data6).
Can someone please help me?
data1 = [297.08,29.54,80.75];
fid = fopen('alldata.txt','w');
fprintf(fid,'%d\t%d\t%d\n',data1');
fprintf(fid,'%d\t%d\t%d\n',data2');
fprintf(fid,'%d\t%d\t%d\n',data4');
fprintf(fid,'%d\t%d\t%d\n',data7');

답변 (1개)

Walter Roberson
Walter Roberson 2013년 9월 27일
Have you considered save() with the -ascii flag ?
Beyond that, see
  댓글 수: 2
Marty Dutch
Marty Dutch 2013년 9월 27일
Many thanks for your repsonse! I hope you can help me getting this further. I tried save() with the ascii flag as you mentioned although I want to be able to do some text formatting. Now I used the code below but I do not get the right values. alldata.txt contains a huge list containing this (=not the data that is in the variables, data1 contains 297.08,29.54,80.75 ):
103.000000 97.000000 117.000000
115.000000 115.000000 105.000000
97.000000 110.000000 115.000000
This is the code I used:
fid = fopen('alldata.txt','w');
for k=1:300
try
textName = ['data', num2str(k)];
fprintf(fid,'%f\t%f\t%f\n',textName');
catch
continue;
end
end
Marty Dutch
Marty Dutch 2013년 10월 1일
Is there someone who can help me pls with my question above?:) Until this last step is not resolved I cannot run analysis:(

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by