for loop, write to text file, append, sprintf, fprintf
Show older comments
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 Comment
Jan
on 23 Jun 2017
In fopen(sprintf('textfile.txt','w'): No "sprintf(" here.
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!