I am having the error while I try to run and angle dependent matrix, "Dimensions of arrays being concatenated are not consistent." My angle is ranging from 0:6:360.

1 view (last 30 days)
zp = -30;
zd = -10;
xv = 10;
yv = 10;
zv = 10;
phi=0:6:360;
Inv_B_RD = [cos(phi) 0 sin(phi) (-xv*cos(phi) -zv*sin(phi)); ...
0 1 0 -yv; ...
-sin(phi) 0 cos(phi) (-zd -zp -zv*cos(phi) + xv*sin(phi)); ...
0 0 0 1];
The above code shows me the error message, "Dimensions of arrays being concatenated are not consistent." I have snderstood the problem and I have tried several time to solve this but as I am new I could not solve it. Thank You !
  1 Comment
Scott MacKenzie
Scott MacKenzie on 19 Jun 2021
Can you describe more clearly what you are trying to do? What is the size and organization of data you want for the Inv_B_RD matrix? At the moment you've got 184 elements in the 1st row and 4 elements in the second row. Hence, the error.
As well, it seems you are defining phi in degrees, but you are using the radian version of the trig functions. You need to use sind and cosd.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 19 Jun 2021
phi=0:6:360;
phi is a vector 1 x 61
Inv_B_RD = [cos(phi) 0 sin(phi) (-xv*cos(phi) -zv*sin(phi)); ...
cos(phi) is a vector, 1 x 61. You then append a scalar 0, then the 1 x 61 vector from sin(phi), then the 1 x 61 vector from the sin cos calculation. Total width of the first row: 61+1+61+61 = 184
0 1 0 -yv; ...
0, 1, 0, and yv are scalars, so this is going to result in a 1 x 4 vector. That is incompatible to put as the second row of a matrix of 184 columns.
Solution:
zp = -30;
zd = -10;
xv = 10;
yv = 10;
zv = 10;
phi = reshape(0:6:360, 1, 1, []); %move it into third dimension
ZE = zeros(size(phi));
ON = ones(size(phi));
Inv_B_RD = [cos(phi), ZE, sin(phi), (-xv*cos(phi) - zv*sin(phi));
ZE, ON, ZE, -yv*ON;
-sin(phi), ZE, cos(phi), (- zd - zp - zv*cos(phi) + xv*sin(phi));
ZE, ZE, ZE, ON
];
This will create a 4 x 4 x 61 matrix, in which the third dimension reflects the different values of phi.
Looking at the name of the variable, you probably intend to do matrix multiplication. You will not be able to do that with the normal * operator, but see pagemtimes()
  3 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!