MATLAB: How to fix error: horzcat dimensions of matrices being concatenated are not consistent

error message

theta=210
sign=(cosd (theta)/abs (cosd (theta)))
u=.8
R=12
c=5
y=18
Id=(.5*Md*R^2)
Mp=75
Mb=30
alpha=0
u=.8
L=6*R
a=[1 0 1 0 0 0 0 0 0 0 0; 0 1 0 1 0 0 0 0 0 0 0; 0 0 -R*sind(theta) R*cosd(theta) 0 0 0 0 0 0 1; 0 0 0 0 1 0 1 0 0 0 0; 0 0 0 0 0 1 0 1 0 0 0; 0 0 0 0 -R*sind(theta) R*cosd(theta) 0 0 0 0 0; 0 0 -1 0 -1 0 0 0 (4*abs(sign)) 0 0; 0 0 0 -1 0 -1 0 0 (-4*u*sign) 0 0; 0 0 -c (3*R) -c (-3*R) 0 0 (-4*(y-c)) 0 0; 0 0 0 0 0 0 0 0 -sign u*sign 0; 0 0 0 0 0 0 0 0 (-u*sign) 1 0]
Error using horzcat Dimensions of matrices being concatenated are not consistent.

Best Answer

I added the definition
Md = 1;
to get your code to run, but then it ran to completion for me. Are you sure you pasted in the line that caused the error?
It's hard for me to diagnose an error that I cannot replicated, but I would suggest checking the sizes of the intermediate variables, to make sure they are what you expect.