MATLAB: Create a matrix with a for loop

equationfor loopMATLABmatrix

Hello all, i am trying to calculate a bunch of matrices using a for loop. I have written the following code
T = 60;
for t = 60:60:12940
phi(:,t) = [(n1(1,t+T)-n2(1,t+T)) / (n1(1,t)-n2(1,t)), (n3(1,t+T)-n4(1,t+T)) / (n3(2,t)-n4(2,t)); (n1(2,t+T)-n2(2,t+T)) / (n1(1,t)-n2(1,t)), (n3(2,t+T)-n4(2,t+T)) / (n3(2,t)-n4(2,t))];
end
i am getting an error code that says the left side of the equation is a 2-by-1 and the right side is a 2-by-2. both sides of the equation are supposed to be a 2-by-2!
How would i go about writing the left side of the eqution so it would work with the for loop and result in a 2-by-2?
Thanks for any help!

Best Answer

T = 60;
phi = cell([],1) ;
count = 0 ;
for t = 60:60:12940
count = count+1 ;
phi{count} = [(n1(1,t+T)-n2(1,t+T)) / (n1(1,t)-n2(1,t)), (n3(1,t+T)-n4(1,t+T)) / (n3(2,t)-n4(2,t)); (n1(2,t+T)-n2(2,t+T)) / (n1(1,t)-n2(1,t)), (n3(2,t+T)-n4(2,t+T)) / (n3(2,t)-n4(2,t))];
end
If you think that always the RHS is a 2x2 matrix, ot can be saved into matrix by initlaizing it into a 3D matrix.