Error with matrix "Error using vertcat" Dimensions of arrays being concatenated are not consistent.
2 views (last 30 days)
Show older comments
It's giving me an error at the beginning of the 10x10 matrix. I've tried everything, but I'm not sure what the problem is.
k = 500; %N/m
mp = 0.2; % Mass of Slider kg
m3 = 5; %kg
IG3 = 0.54; %kg*m^2
m2 = 1.5; %kg
IG2 = 0.125; %kg*m^2
w2 = 10; %rad/s
a2 = 0; %rad/s^2
O2A = 1; %m
AB = 5; %m
AG3 = 3; %ma
BG3 = 2.18; %m
G2 = O2A/2; %distance to cg on link 2
a = O2A;
b = AB;
c = 2; %m
thet2 = 30; %deg
theta2 = 0:1:360;
%Position Analysis
theta3 = asind((a.*sind(theta2)-c)./b);
d = a.*cosd(theta2)-b.*cosd(theta3);
%Velocity Analysis
w3 = ((a.*cosd(theta2))./(b.*cosd(theta3))).*w2;
vB = (-a.*w2.*sind(theta2))+(b.*w3.*sind(theta3));
%Acceleration Analysis
a3 = (a.*a2.*cosd(theta2)-a.*(w2.^2).*sind(theta2)+b.*(w3.^2).*sind(theta3))./b.*cosd(theta3);
aB = -a.*a2.*sind(theta2)-a.*(w2.^2).*cosd(theta2)+b.*a3.*sind(theta3)+b.*(w3.^2).*cosd(theta3);
delta3 = 12.859; %deg from b to line AG3
AG3x = (-a.*(w2.^2).*cosd(theta2)-a.*a2.*sind(theta2)-AG3.*(w3.^2).*cosd(theta3-180+delta3)-AG3.*a3.*sind(theta3-180+delta3));
AG3y = (-a*(w2.^2).*sind(theta2)+a.*a2.*cosd(theta2)-AG3.*(w3.^2).*sind(theta3-180+delta3)+AG3.*a3.*cosd(theta3-180+delta3));
AG3mag = sqrt((AG3x.^2)+(AG3y.^2));
%Position Vectors
R12x = O2A./2.*cosd(180+theta2);
R12y = O2A./2.*sind(180+theta2);
R32x = O2A./2.*cosd(theta2);
R32y = O2A./2.*sind(theta2);
R23x = AG3.*cosd(theta3);
R23y = AG3.*sind(theta3);
R43x = BG3.*cosd(theta3+149.306);
R43y = BG3.*sind(theta3+149.306);
%Acceleration Vectors
AG2x = (-a/2.*w2.^2.*cosd(theta2)-a./2.*a2.*sind(theta2));
AG2y = (-a/2.*w2.^2.*sind(theta2)-a./2.*a2.*cosd(theta2));
AG4x = -(BG3).*w3.^2.*cosd(theta3) - (BG3).*a3.*sind(theta3);
AG4y = -(BG3).*w3.^2.*sind(theta3) - (BG3).*a3.*cosd(theta3);
Fp4y = 0;
Fp4x = 0;
for i = 1:361
M = [1 0 1 0 0 0 0 0 0 m2*AG2x(1,i)
0 1 0 1 0 0 0 0 0 m2*AG2y(1,i)
-R12y(1,i) R12x(1,i) -R32y(1,i) R32x(1,i) 0 0 0 0 0 IG2*a2(1,i)
0 0 -1 0 1 0 0 0 0 m3*AG3x(1,i)
0 0 0 -1 0 1 0 0 0 m3*AG3y(1,i)
0 0 R23y(1,i) -R23x(1,i) -R43y(1,i) R43x(1,i) 0 0 1 IG3*a3(1,i)
0 0 0 0 -1 0 1 0 0 mp*AG4x-Fp4x(1,i)
0 0 0 0 0 -1 0 1 0 mp*AG4y-Fp4y(1,i)
0 0 0 0 0 0 1 0 0 0]
forces = rref(M);
F12x(1,i) = forces(1,10);
F12y(1,i) = forces(2,10);
F32x(1,i) = forces(3,10);
F32y(1,i) = forces(4,10);
F43x(1,i) = forces(5,10);
F43y(1,i) = forces(6,10);
F14x(1,i) = forces(7,10);
F14y(1,i) = forces(8,10);
T12(1,i) = forces(9,10);
end
0 Comments
Accepted Answer
Stephen23
on 27 Oct 2021
Edited: Stephen23
on 28 Oct 2021
The problems are on these lines:
0 0 0 0 -1 0 1 0 0 mp*AG4x-Fp4x(1,i)
0 0 0 0 0 -1 0 1 0 mp*AG4y-Fp4y(1,i)
Because AG4x and AG4y are row vectors with 361 elements each and mp is scalar both of those rows will have 370 elements (columns), which you then attempt to vertically concatenate with all of the other matrix rows (which each have 10 columns). My guess is that you need to index them:
0 0 0 0 -1 0 1 0 0 mp*AG4x(i)-Fp4x(1,i)
0 0 0 0 0 -1 0 1 0 mp*AG4y(i)-Fp4y(1,i)
Once you fix that bug you will get an other error because a2, Fp4x, Fp4y (and possibly other variables) are scalar, but you attempt to index into ithem as if they have 361 elements.
3 Comments
Walter Roberson
on 28 Oct 2021
Fp4y = 0;
Fp4x = 0;
Do those have 361 columns? Did you assign to Fp4y and Fp4x somewhere else in the program?
Stephen23
on 28 Oct 2021
Edited: Stephen23
on 28 Oct 2021
"When I tried that, it gives me another error on that line saying "Index in position 2 exceeds array bounds (must not exceed 1).""
Yes, I already explained the cause of that in my answer. I guess you will have to ask the author of the code to explain those variables and why they used scalars when their indexing clearly expects 361 elements.
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!