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!