MATLAB: Matrices Dimensions Not Consistent when t=0:10

concatenatedimensionfor loopmatricesmatrix

Hi,
I don't understand why it says it's not consistent. It's a 4*4 matrix. Only the element depents on t grows, but not the whole matrix?
So if I want to grow it, I have to use for loop? Thanks!
t= 1:10;
psm_x_dsr = [1 0 0 0.25*(1-cos(pi*t));
0 1 0 0.25*(1-sin(pi*t));
0 0 1 0;
0 0 0 1];
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Error in main (line 15)
psm_x_dsr = [1 0 0 0.25*(1-cos(pi*t)); 0 1 0 0.25*(1-sin(pi*t)); 0 0 1 0; 0 0 0 1]';

Best Answer

YOu need to store the result into a 3D matrix.
t= 1:10;
nt = length(t) ;
psm_x_dsr = zeros(4,4,nt) ;
for i = 1:nt
psm_x_dsr(:,:,i) = [1 0 0 0.25*(1-cos(pi*t(i)));
0 1 0 0.25*(1-sin(pi*t(i)));
0 0 1 0;
0 0 0 1];
end