Index exceeds the number of array elements (0).

조회 수: 2 (최근 30일)
Preston Stinnett
Preston Stinnett 2021년 12월 4일
I keep getting the error mentioned above. Index exceeds the number of array elements (0). Error (line 46) T4=RobotConv (0,L(k),0,0);
I have been trying to fix this but cannot get it to work. Does anyone have any tips on this?
clc;
clear all;
display('Joint 1');
display('=======================');
angle1=input('Please key in theta_1 (degree):');
d1=input('Please key in distance_1 (d):');
al1=input('Please key in alpha_1 (degree):');
display('Joint 2');
display('=======================');
angle2=input('Please key in theta_2 (degree):');
d2=input('Please key in distance_2 (d):');
al2=input('Please key in alpha_2 (degree):');
display('Joint 3');
display('=======================');
angle3=input('Please key in theta_3 (degree):');
d3=input('Please key in the minimum distance_3 (d):');
d4=input('Please key in the maximum distance_3 (d):');
al3=input('Please key in alpha_3 (degree):');
display('Joint 4');
display('=======================');
angle4=input('Please key in theta_4 (degree):');
d4=input('Please key in distance_4 (d):');
al4=input('Please key in alpha_4 (degree):');
L1=min(d3);
L2=max(d4);
L3=d4;
theta1=0:angle1/100:angle1;
theta2=0:angle2/100:angle2;
theta3=0:angle3/100:angle3;
L=L2:(L3-L2)/100:L3;
framemax=100;
M=moviein(framemax);
set(gcf,'Position',[100 100 640 480]);
for k=1:framemax
T1=RobotConv(theta1(k), d1, 0, al1);
T2=RobotConv(theta2(k), d2, 0, al2);
T3=RobotConv(theta3(k), d3, 0, al3);
T4=RobotConv(0, L(k), 0, 0);
p0=[0 0 0];
p1=RobotPosition(T1);
p2=RobotPosition(T1*T2);
p3=RobotPosition(T1*T2*T3);
p4=RobotPosition(T1*T2*T3*T4);
figure(1)
X=[p0(1) p1(1) p2(1) p3(1)];
Y=[p0(2) p1(2) p2(2) p3(2)];
Z=[p0(3) p1(3) p2(3) p3(3)];
subplot(221),plot3(X,Y,Z,'o-')
axis([-10 10 -10 10 0 10]);
grid
subplot(222),plot(X,Y,'o-')
axis([-10 10 -10 10]);
title('X-Y')
grid
subplot(223),plot(X,Z,'o-')
axis([-10 10 0 10]);
title('X-Z')
grid
subplot(224),plot(Y,Z,'o-')
axis([-10 10 0 10]);
title('Y-Z')
grid
M(k)=getframe(gcf);
end
function P = RobotPosition(T)
x = T(1,4);
y = T(2,4);
z = T(3,4);
P = [x y z];
end
function T = RobotConv(theta,d,a,alpha)
rad = pi/180;
M_theta = [cos(theta*rad) -sin(theta*rad) 0 0;sin(theta*rad) cos(theta*rad) 0 0;0 0 1 0;0 0 0 1];
M_d = [1 0 0 0;0 1 0 0;0 0 1 d;0 0 0 1];
M_a = [1 0 0 a;0 1 0 0;0 0 1 0;0 0 0 1];
M_alpha = [1 0 0 0;0 cos(alpha*rad) -sin(alpha*rad) 0;0 sin(alpha*rad) cos(alpha*rad) 0; 0 0 0 1];
T=M_theta*M_d*M_a*M_alpha;
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by