Writing results of a loop to a vector
Show older comments
I'm trying to create a loop that writes filenames, and it works but overwrites the variable. How do I get it to save the results to an entry in a vector?
%% Problem 4
myfile=zeros(1000,1);
for q=1:1000
if q<=9
myfile=sprintf('data_00000%d.dat',q);
elseif(q>9 && q<=99)
myfile=sprintf('data_0000%d.dat',q);
elseif(q<=999 && q>99)
myfile=sprintf('data_000%d.dat',q);
else
myfile=sprintf('data_00%d.dat',q);
end
end
I know im supposed to add (q) as a function of a variable but I don't know where. If I add it after "myfile" I get the error: "In an assignment A(I) = B, the number of elements in B and I must be the same.
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!