for loop, write to text file, append, sprintf, fprintf
古いコメントを表示
Hi, I want to make a for_loop that adds lines to a text file.
first loop: direction_lights_1 = [1 2 3] second loop: direction_lights_2 = [4 5 6] ... fifth loop: direction_lights_5 = [13 14 15]
My code so far looks like this:
fileID = fopen(sprintf('textfile.txt','w'); %here I create the text file
fprintf(fileID, '%f %f %f \n', direction_lights); %here I print the 3 numbers and then go to a new line
fclose(fileID);
Now I want the program to append lines to the existing text file. It should look somewhat like this:
for i=1:5 %obviously open the file again
fprintf(fileID, '%f %f %f \n', direction_lights_i.'a');
end
I can't figure out how to make it work. Hope it is clear what I'm trying to achieve. Thanks for your help! J
1 件のコメント
Jan
2017 年 6 月 23 日
In fopen(sprintf('textfile.txt','w'): No "sprintf(" here.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および 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!