Writing data to file
古いコメントを表示
Dear all,
I am writing data to a .txt file as follows:
fid = fopen('test.txt', 'wt');
for n = 1:length(z)
for j=1:13
fprintf(fid, 'Si %g %g %g\n', x(j,n), y(j,n),z(j,n));
end
end
fclose(fid);
Which is working lovely - absolutely as intended. The only problem is that this code is contained within another for loop, which resets the old values of x,y,z and puts some new ones in each time the loop interates, so what ends up happening is that I only get the x, y and z values for the last interation of the loop in my file, but I need all of the values.
Is there a way I can get Matlab to start writing the new x,y,z values on a clean line rather than overwriting the old data already in the file? Or perhaps a piece of code I can add to my loop above to implement this another way?
Thanks for any help.
回答 (1 件)
Walter Roberson
2011 年 3 月 8 日
1 投票
If you change the 'wt' to 'at' then the file will be appended to each time.
1 件のコメント
Jan
2011 年 3 月 8 日
Simple, exact, exhaustive. +1
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!