MATLAB: Storing a 100×100 matrix from each iteration in a single new matrix

iterationsloopsMATLABmatrix

I am running a loop 100 times, and within that i produce a 100×100 matrix (this represents topography, each loop is a pperiod in time).
I would like to store every outut of that loop into a single matrix, as well as its assigned iteration number.
i.e. 100, 100×100 matricies, all assigned to their iteration number.
Topography, 1
Topoography, 2 , etc all in one matrix
I am led to beleive this is possible, but have no idea how to do it!

Best Answer

Two options -- either use a cell array each element of which is a 2D array or a 3D array in which each plane is one time step. Being a fan of using cell arrays only when necessary, I'd most likel choose to go that route which would look like --
N=100; % set the counter in a variable, don't bury "magic" numbers in code -- can change just data, not code
T=zeros(N,N,N); % preallocate for speed
for i=1:N
T(:,:,i)=yourfunction(i); % compute the output arrays, store by plane
end