# calculating the index in a FOR loop

I am coding in Matlab:

m = [40 50 60]; X=[];        % [] makes an empty matrix
for j=1:3
for i=1:3
x=zeros(m(i),1);     % a vector of m(i) zeros
X=[X;x];             % store x under the old previous ones
end
end


and would like to run the code in parallel. Is there a way to calculate from which index to which index in X I will be in a given loop storing in please?

• Your question is a bit hard to understand. Perhaps the answer that you're looking for is that $x$ is inserted as row number $3(j-1)+i$ at the $(i,j)$th iteration. – Yuval Filmus Oct 11 '19 at 14:19
• thank you very much. that's it :-) – Rafael Oct 17 '19 at 17:20