how to store a vector that i got from a for loop ?

i need put all results in the same vector, the vector A only show me the last result in the for loop
for i=1:3
a=[2+i,i]
d=[5+2*i, 3*i]
endfor
A=[a' d' ]

2 Comments

yes it is, my question alredy was answered, thank you :)

Sign in to comment.

 Accepted Answer

Hi,
Here is the solution to your loop based script to save all values:
for i=1:3
a(i, :)=[2+i,i]
d(i, :)=[5+2*i, 3*i]
end
A=[a' d' ]
Good luck.

6 Comments

thak you for your help , i appreciate it, i really needed this for my job, great. :)
Note: Always preallocate the variable before loop.
@ Sandra: did u accept it?
i did my code like your answer, but i modified one thing.
for i=1:3
a(i,:)=[2+i,i]
d(i,:)=[5+2*i, 3*i]
endfor
A=[a ; d ]
and its working perfectly. Thank you
endfor is not a valid MATLAB syntax.
@ Sandra: but you didn't hit accept .. :) . Good luck.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB 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!