MATLAB: How to store arrays from a for loop in a single matrix

array

i have this code as an example
for n=1:4
g=n+1
r=n+2
e=n+3
c=n+4
A=[g r;e c]
W(n,:)=A
end
So i am trying to store every A produced in a matrix form as the program loops from 1 to 4 but to no avail. So can you help me.

Best Answer

N = 4 ;
A = zeros(2,2,N) ;
for n=1:N
g=n+1 ;
r=n+2 ;
e=n+3 ;
c=n+4 ;
A(:,:,n)=[g r;e c] ;
end
A
Related Question