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 (최근 30일)
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
Scott MacKenzie
Scott MacKenzie 2021년 6월 19일
편집: Scott MacKenzie 2021년 6월 19일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2021년 6월 19일
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
Walter Roberson
Walter Roberson 2021년 6월 19일
Works fine when I try. Did you copy and paste?
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
];
size(Inv_B_RD)
ans = 1×3
4 4 61
If it still fails after you copy and paste, then what shows up for
which -all cos

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Trigonometry에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by