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)];

조회 수: 4 (최근 30일)
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
Stephen23
Stephen23 2019년 12월 4일
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).

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

답변 (1개)

Walter Roberson
Walter Roberson 2019년 12월 4일
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.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by