# Why do I get the error “Dimensions of arrays being concatenated are not consistent.”?

2 views (last 30 days)
Sara Jones on 19 Jul 2019
Answered: Ivan Dwi Putra on 27 Nov 2019
I am attempting to write a program that plots the kiinematic workspace for a robot with 7 degrees of freedom, however the error 'Dimensions of arrays being concatenated are not consistent.' arises for the following piece of code (this error relates to the line T = [ cos(d) -sin(d)*cos(b))
a1 = 0; alpha1 = pi/2; d1 = 0.0345;
a2 = 0; alpha2 = -pi/2; d2 = 0;
a3 =-0.045; alpha3 = pi/2; d3 = 0.55;
a4 = 0.045; alpha4 = -pi/2; d4= 0;
a5 = 0; alpha5 = -pi/2; d5 = 0.30;
a6 = 0; alpha6 = pi/2; d6 = 0;
a7 = 0; alpha7 = 0; d7 =0.060;
t1_min = 0; t1_max = 0;
t2_min = -1.9; t2_max = 1.9;
t3_min = -2.8; t3_max = 2.8;
t4_min = -0.9; t4_max = 3.14;
t5_min = -4.8; t5_max = 1.3;
t6_min = -1.6; t6_max = 1.6;
t7_min = -2.2; t7_max = 2.2;
N = 20000;
t1 = t1_min + (t1_max-t1_min)*rand(N,1);
t2 = t2_min + (t2_max-t2_min)*rand(N,1);
t3 = t3_min + (t3_max-t3_min)*rand(N,1);
t4 = t4_min + (t4_max-t4_min)*rand(N,1);
t5 = t5_min + (t5_max-t5_min)*rand(N,1);
t6 = t6_min + (t6_max-t6_min)*rand(N,1);
t7 = t7_min + (t7_max-t7_min)*rand(N,1);
for i = 1:N
A1 = TransMat(a1,alpha1,d1,t1(i));
A2 = TransMat(a2,alpha2,d2,t2(i));
A3 = TransMat(a3,alpha3,d3,t3(i));
A4 = TransMat(a4,alpha4,d4,t4(i));
A5 = TransMat(a5,alpha5,d5,t5(i));
A6 = TransMat(a6,alpha6,d6,t6(i));
A7 = TransMat(a7,alpha7,d7,t7(i));
T = A1*A2*A3*A4*A5;
X=T(1,4);
Y=T(2,4);
Z=T(3,4);
plot3(X,Y,Z,'.')
hold on;
view(3);
title('Isometric view');
xlabel('x (m)');
end
function [ T ] = TransMat( a,b,c,d )
T = [ cos(d) -sin(d)*cos(b)
sin(d)*sin(b) a*cos(d); sin(d)
cos(d)*cos(b) -cos(d)*sin(b) a*sin(d);
0 sin(b) cos(b) c;
0 0 0 1
];
end

Torsten on 19 Jul 2019
T = [ cos(d), -sin(d)*cos(b), sin(d)*sin(b), a*cos(d);
sin(d), cos(d)*cos(b), -cos(d)*sin(b), a*sin(d);
0, sin(b), cos(b), c;
0, 0, 0, 1];

### More Answers (1)

Ivan Dwi Putra on 27 Nov 2019
close all
% Initial Conditions
% x0 = [3; % 3 radians
% 0]; % 0 rad/s
%Parameter Massa
m1 = 650; % massa train set 1 dalam kg
m2 = 650; % massa train set 2 dalam kg
%Parameter Gaya
f1 = 1170; % dalam N
f2 = 1170; % dalam N
t = [0:100:1000];
% System Dynamics
% a = f1./m1 - (0.004 + (0.00032.*(1.5-(0.015.*sin(0.2.*t)-50))));
% b = f2./m2 - (0.0025 + (0.0004.*(1.6-(0.01.*sin(0.3.*t)-50))));
A = [0 1 0 0;
0 f1./m1 - (0.004 + (0.00032.*(1.5-(0.015.*sin(0.2.*t)-50)))) 0 0;
0 0 0 1;
0 0 0 f2./m2 - (0.0025 + (0.0004.*(1.6-(0.01.*sin(0.3.*t)-50))))
];
B = [0;
1/m1
0
1/m2];
C = [1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1];
D = 0;
% Control Law
Q = [1 0 0 0;
0 1 0 0
0 0 1 0
0 0 0 1];
R = [1 0 0 0;
0 1 0 0
0 0 1 0
0 0 0 1];
K = lqr(A,B,Q,R);
% Closed loop system
sys = ss((A - B*K), B, C, D);