Error using ==> horzcat CAT arguments dimensions are not consistent. Help please !

2 visualizzazioni (ultimi 30 giorni)
Hello Matlab community !
I am working on kinematics for a 3DOF finger. I recently made a small program which moves the finger from one spot to another.For example from spot A(x1,y1) to B(x2,y2).
The problem i have with the program is that if x1=x2 or y1=y2 I get an error which says "
"??? Error using ==> horzcat
CAT arguments dimensions are not consistent.
Error in ==> move at 72
C=[ones(size(B))*A1,A2] "
This is the program i have made.
------------------------------------------------------------
function move(X1,Y1,X2,Y2,phi)
%example move(8,4,4,3,0)
%dimensions of the finger bones
l1=3.9;
l2=6.2;
l3=4.7;
%i do that cause i don't know if i will move from A->B or B->A
GB=abs(X1-X2);
AG=abs(Y1-Y2);
%it is like I create a triangle ABG and i have, AG=Y=|Y1-Y2|
and GB=X=|X1-X2|
B=20;
%i do that cause i want to have 20 points from A->G and G->B
if X1>X2;
A1=Linspace(X1,X2,B);
elseif X1<X2;
A1=Linspace(X1,X2,B);
else
A1=[ones(size(B))*X1];
end
A1=A1'
if Y1>Y2;
A2=Linspace(Y1,Y2,B);
elseif Y1<Y2;
A2=Linspace(Y1,Y2,B);
else
A2=[ones(size(B))*Y1];
end
A2=A2'
%--------------------------------------------------------------------
% C= [20 points GB , 20 points AG]
C=[ones(size(B))*A1,A2]
%----------------------------------------------------------------
%--------------------------kinematics-------------------------
i=1;
for i=1:B
Px=C((i),1);
Py=C((i),2);
%respectively (x,y)
phi=phi*pi/180;
sigma=(Px^2+Py^2+l3^2-l1^2-l2^2-2*l3*(Px*cos(phi)+Py*sin(phi)))/2/l1/l2;
Q2=atan2(+sqrt(1-sigma^2),sigma);
num1=(Py-l3*sin(phi)) * (l1+l2*cos(Q2)) - (Px-l3*cos(phi))*l2*sin(Q2);
den=(l1^2+l2^2+2*l1*l2*cos(Q2));
num2=(Px-l3*cos(phi))*(l1+l2*cos(Q2))+(Py-l3*sin(phi))*l2*sin(Q2);
Q1=atan2(num1/den,num2/den);
Q3=phi-Q1-Q2;
Q1=Q1*180/pi;
Q2=Q2*180/pi;
Q3=Q3*180/pi;
Q((i),1)=Q1;
Q((i),2)=Q2;
end
grid on
j=1;
for j=1:B,
q1=Q((j),1);
q2=Q((j),2);
q3=Q((j),3);
q1=q1*pi/180;
q2=q2*pi/180;
q3=q3*pi/180;
x=l1*cos(q1)+l2*cos(q1+q2)+l3*cos(q1+q2+q3);
y=l1*sin(q1)+l2*sin(q1+q2)+l3*sin(q1+q2+q3);
f=q1+q2+q3;
x1=l1*cos(q1);
x2=l1*cos(q1)+l2*cos(q1+q2);
y1=l1*sin(q1);
y2=l1*sin(q1)+l2*sin(q1+q2);
line( [0 x1 x2 x], [0 y1 y2 y], [ 0 0 0 0 ])
hold on
plot(0,0,'o')
plot(x1,y1,'o')
plot(x2,y2,'o')
plot(x,y,'o','LineWidth',30)
AXIS([-3 15.13 -3 15.13])
pause(0.2)
end
end
Thanks a lot in advance !

Risposta accettata

Honglei Chen
Honglei Chen il 27 Gen 2012
When x1=x2 but y1~=y2, your A1 is a scalar but A2 is a column vector, hence it cannot be concatenated. Similar thing for x1~=x2 but y1=y2. But you should be able to easily figure this out if you simply put a breakpoint at the error out line and test the dimension of A1 and A2.
  3 Commenti
Honglei Chen
Honglei Chen il 27 Gen 2012
Note that the error message says that the dimensions do not match, so this means ones(size(B))*A1 and A2 have different sizes. In addition, the error says that it errors out at line 72. Therefore, if you are using MATLAB editor, you can click on the left of line 72 and that will put a break point there. You then run your program again and the program will stop at line 72. This way you can, for example, do a whos in the command line to examine the size of different variables.
If you don't use MATLAB desktop, then you will have to rely on dbstop in command line.
For more information on how to debug in MATLAB, here is a good tech notes: http://www.mathworks.com/help/techdoc/matlab_prog/f10-60570.html
HTH
Nikolaos
Nikolaos il 27 Gen 2012
Hello again !
Well not only you solved my problem but also i learned some new stuff that i am gonna use in the future in Matlab.
Thanks a lot for your time and effort! I really appreciate it :)
Take care Honglei Chen , best of luck to you !

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by