I keep getting this error: Error using vertcat Dimensions of arrays being concatenated are not consistent. Error in ME450_project_linkage (line 16) P5_pos = D*[0;-1+sin(theta)];
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to model a knuckle linkage system and I keep getting the error that the array dimensions are not consistent fro some reason. Additionally, matlab wont let me model the motion of a certain point (P5_pos). When I try to it gives me the error. Here is the code. It's not finished.
clear
clc
A = 8.25; %in
B = 48;
C = 42;
D = 20;
t = 0:0.01:20; %sec
omega = 5.0265; %rad/sec
theta = omega*t;
P1_pos = [56.25;43.1];
P2_pos = [56.25-A*cos(theta);43.1-A*sin(theta)];
P4_pos = C*[0;1];
P5_pos = D*[0;-1+sin(theta)];
E = sqrt(A^2 + D^2 - 2*A*D*cos(theta));
a = asin(A*sin(theta)./E);
b = acos(E.^2 + C^2 - B^2)./(2*E*C);
P3_pos = [C + B*cos(a+b); B*sin(a+b)];
P5x = P5_pos(1,:);
P5y = P5_pos(:,1);
P5vx = diff(P5x);
P5vy = diff(P5y);
P5v = sqrt(P5vx^2 + P5vy^2);
for i = length(t)
ani = subplot(2,1,1);
P1_pos_cir = viscircles(P1_pos',0.05);
P2_pos_cir = viscircles(P2_pos(:,i)',0.05);
P4_pos_cir = viscircles(P4_pos',0.05);
P5_pos_cir = viscircles(P5_pos',0.05);
P3_pos_cir = viscircles(P3_pos(:,i)',0.05);
barA = line([P1_pos(1) P2_pos(1,i)],[P1_pos(2) P2_pos(2,i)]);
barB = line([P2_pos(1,i) P3_pos(1,i)],[P2_pos(2,i) P3_pos(2,i)]);
barC = line([P3_pos(1,i) P4_pos(1)],[P3_pos(2,i) P4_pos(2)]);
barD = line([P3_pos(1,i) P5_pos(1)],[P3_pos(2,i) P5_pos(2)]);
axis(ani,'equal');
set(gca,'XLim',[-10 60],'YLim',[-30 60]);
pause(0.005);
end
1 comentario
Stephen23
el 4 de Dic. de 2019
theta has size 1x2001.
Zero has size 1x1.
On this line you try to vertically concatenate them together:
P5_pos = D*[0;-1+sin(theta)];
Arrays can only be vertically concatenated if they have the same number of columns: do 1x2001 and 1x1 have the same number of columns (hint: no).
Respuestas (1)
Walter Roberson
el 4 de Dic. de 2019
P5_pos = D*[0;-1+sin(theta)];
Your theta is 1 x 2001, so -1+sin(theta) is 1 x 2001. You are trying to create an array with two rows, one of which is a scalar 0, and the other of which is 1 x 2001 . 1 x 1 (the zero) does not have the same number of columns as 1 x 2001, so the attempt fails.
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!