Storing results from a for loop
1 view (last 30 days)
Show older comments
hi, i would like to store the data of a calculation done in a for loop similarly to this http://blogs.mathworks.com/videos/2011/03/09/how-to-store-a-series-of-vectors-from-a-for-loop/ .specifically i need to create a row vector for my results as it is shown in the following code: for x=1:4; for y=1:4; f=2*x+y-1; matf(:,x*y)=f; end end
I run the code without matf(:,x*y), by writing f(x,y) so i know that the correct answer should be: matf=2 4 6 8 3 5 7 9 4 6 8 10 5 7 9 11
Instead of that i get: matf=2 4 6 8 0 7 0 9 8 0 0 10 0 0 0 11
I 'm thinking it must be something with the y iretation but i can't figure it out. can you please help me out?
0 Comments
Accepted Answer
Wayne King
on 3 Dec 2013
Edited: Wayne King
on 3 Dec 2013
k = 1;
for x=1:4; for y=1:4;
f(k)=2*x+y-1;
k = k+1;
end
end
Now look at f
More Answers (0)
See Also
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!