MATLAB: How to use for loop for iterations.

for loopiteration

for i=1:3
a=rand(3,1);
b=5.*(a.^2);
c=[a b]
end
At the end i get a value of c that is of the order of 3×2, that is the final value that comes after3rd iteration. So value of c gets changed in each iteration. How I can get all value of c of the loop. In other words i want to get c of the order 9×2 (3 iterations and three values for each iteration).

Best Answer

c=[];
for i=1:3
a=rand(3,1);
b=5.*(a.^2);
c=[c;a b]
end
%or
c=zeros(9,2);
ii=1
for i=1:3
a=rand(3,1);
b=5.*(a.^2);
n=size(a,1);
c(ii:ii+n-1,:)=[a b]
ii=ii+3;
end