MATLAB: Dimensions of matrices being concatenated are not consistent

dimension of matricesnot consistent

t = 0:5640; % time taken for the system to run is from 0 to 5640s
i = 83*pi/180; % inclination angle in rad
w0 = 0.0011; % angular velocity in rad/s
a1 = sin(i)*cos(w0*t);
a2 = -cos(i);
a3 = 2*sin(i)*sin(w0*t);
A = [0 -a3 a2; a3 0 -a1; -a2 a1 0];
This is my coding and I would like to create a matrix A. It shows the error Error using vertcat: Dimensions of matrices being concatenated are not consistent when I computed it. I know the reason why, but how can I compute a matrix A with varying number of a1 and a3 while a2 is a constant?

Best Answer

In MATLAB, rows of a matrix cannot have different number of elements. For that, you will need to use a cell array
t = 0:5640; % time taken for the system to run is from 0 to 5640s
i = 83*pi/180; % inclination angle in rad
w0 = 0.0011; % angular velocity in rad/s
a1 = sin(i)*cos(w0*t);
a2 = -cos(i);
a3 = 2*sin(i)*sin(w0*t);
A = {[0 -a3 a2]; [a3 0 -a1]; [-a2 a1 0]};