MATLAB: How to replace use of cell storage with use of arrays

arrayscell arraysfor loopMATLAB

Thanks for taking the time to read this. This is a part of the script I'm working on:
resultX0=cell(length(n),length(q), ntrials);
resultY0=cell(length(n),length(q), ntrials);
resultG=cell(length(n),length(q), ntrials);
for i=1:length(n)
for j=1:length(q)
for k=1:1:ntrials
[G,X0,Y0]=matrix_plantsubm(M,N,c,n(i),p,q(j));
resultX0{i,j,k}=X0;
resultY0{i,j,k}=Y0;
resultG{i,j,k}=G;
end
end
end
I would like to replace use of cell storage with use of arrays (e.g. resultG{i,j,k} = G). I want to run the function 10 times (in this case ntrials) for each value q and n. How can I do that?
Thanks

Best Answer

According to a previous time you posted about matrix_plantsubm.m on Matlab Answers (thanks Google!), it looks like G, X0, and Y0 are all MxN matrices. Therefore, you could declare resultX0, resultY0, and resultG as follows:
resultX0 = zeros(length(n), length(q), ntrials, M, N);
resultY0 = zeros(length(n), length(q), ntrials, M, N);
resultG = zeros(length(n), length(q), ntrials, M, N);
Then your for-loops should look like this:
for i=1:length(n)
for j=1:length(q)
for k=1:ntrials
[G,X0,Y0]=matrix_plantsubm(M,N,c,n(i),p,q(j));
resultX0(i,j,k,:,:)=X0;
resultY0(i,j,k,:,:)=Y0;
resultG(i,j,k,:,:)=G;
end
end
end
Hope this helps!