Storing results from a for loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Wayne King
am 3 Dez. 2013
Bearbeitet: Wayne King
am 3 Dez. 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!