MATLAB: How to save vector output from for loop

for loopMATLAB

For i=1:10 A=[i i+1 i+2; i+1 i i+1; i+2 i+1 i]; end
Now I want to make a new matrix Such that it's first element is the output of loop's eleration and so on.
Like this B = [A1 A2 A3…..A10 ]

Best Answer

Save it as a 3D matrix:
A=zeros(3,3,10); % pre-allocate
for k = 1:10
A(:,:,k)=[k k+1 k+2; k+1 k k+1; k+2 k+1 k];
end