fprintf in a for loop
Show older comments
I wrote this function to write all numbers w(i) in a text document.
But as you can see the program only writes the last number w(12) = 2^12 in the document.
What can I do to get all w(i) into the document?
function test
N = 12;
k = 2;
for i = 1:N-1
w(i) = k^i;
w(i)
fid = fopen('Test2.txt', 'w');
fprintf(fid, '%s\n', 'Data w');
fprintf(fid, '%6.4f\t', w(i));
fclose(fid);
end
end

Accepted Answer
More Answers (0)
Categories
Find more on Cell Arrays 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!