im currently still learning how to do Matlab why do i getting Index in position 1 exceeds array bounds. Index must not exceed 6? (line 51) Rob.plot(y(i,:));
    7 views (last 30 days)
  
       Show older comments
    
    Timothy Ambun
 on 17 Jun 2022
  
    
    
    
    
    Commented: Timothy Ambun
 on 18 Jun 2022
            clear all;
% Robot Kinematics
% Robot dimension
L1 = 0.4; L2 =0.5; L3 = 0.4; d1 = 0.05;
%DH Parameters
L(1) = Link([0 L1 0 1.5708])
L(2) = Link([0 0 L2 0 ])
L(3) = Link([0 0 L3 0 ])
%Link Robot using serialink
Rob=SerialLink(L);
Rob.name = ('Group7')
P = transl(2.338e-06, 0.5365, 1.036)
P1= transl(0.1, 0.3, -0.3)
P2= transl(0.4, -0.2, 0.1)
P3= transl(-0.4, 0.4, -0.3)
P4= transl(-0.3,-0.3, 0.2)
q0=[0 0 0];
%Inverse
I=Rob.ikine(P,'q0',[0 0 0],'mask',[1 1 1 0 0 0]);
I1=Rob.ikine(P1,'q0',[0 0 0],'mask',[1 1 1 0 0 0]);
I2=Rob.ikine(P2,'q0',[0 0 0],'mask',[1 1 1 0 0 0]);
I3=Rob.ikine(P3,'q0',[0 0 0],'mask',[1 1 1 0 0 0]);
I4=Rob.ikine(P4,'q0',[0 0 0],'mask',[1 1 1 0 0 0]);
%Trajectory
t=0:0.04:0.2;
y=jtraj(q0,I,t);
y1=jtraj(I,I1,t);
y2=jtraj(I1,I2,t);
y3=jtraj(I2,I3,t);
y4=jtraj(I3,I4,t);
y5=jtraj(I4,q0,t);
hold on
atj=zeros(4,4);
view(3)
for i = 1:1:51
    atj=Rob.fkine(y(1,:));
    jta=transl(atj);
    JTA(i,:) = jta;
    jta=JTA;
    plot2(jta(i,:),'r.')
    Rob.plot(y(i,:));
    plot2 (JTA,'b')
end
for i= 1:1:51
    atj1=Rob.fkine(y1(1,:));
    jta=transl(atj1);
    JTA1(i,:) = jta;
    jta=JTA1;
    plot2(jta(i,:),'r.')
    Rob.plot(y1(i,:))
    plot2 (JTA1,'b')
end
for i= 1:1:51
    atj2=Rob.fkine(y2(1,:));
    jta=transl(atj2);
    JTA2(i,:) = jta;
    jta=JTA2;
    plot2(jta(i,:),'r.')
    Rob.plot(y1(i,:))
    plot2 (JTA2,'b')
end
for i= 1:1:51
    atj3=Rob.fkine(y3(1,:));
    jta=transl(atj3);
    JTA3(i,:) = jta;
    jta=JTA3;
    plot2(jta(i,:),'r.')
    Rob.plot(y3(i,:))
    plot2 (JTA3,'b')
end
for i= 1:1:51
    atj4=Rob.fkine(y4(1,:));
    jta=transl(atj4);
    JTA4(i,:) = jta;
    jta=JTA4;
    plot2(jta(i,:),'r.')
    Rob.plot(y4(i,:))
    plot2 (JTA4,'b')
end
for i= 1:1:51
    atj5=Rob.fkine(y5(1,:));
    jta=transl(atj5);
    JTA5(i,:) = jta;
    jta=JTA5;
    plot2(jta(i,:),'r.')
    Rob.plot(y5(i,:))
    plot2 (JTA5,'b')
end
0 Comments
Accepted Answer
  Geoff Hayes
      
      
 on 17 Jun 2022
        for i = 1:1:51
    atj=Rob.fkine(y(1,:));
    jta=transl(atj);
    JTA(i,:) = jta;
    jta=JTA;
    plot2(jta(i,:),'r.')
    Rob.plot(y(i,:));
    plot2 (JTA,'b')
end
since i iterates from 1 to 51, then when i is 7, you will observe this error. You should be able to use the MATLAB debugger to confirm that y only has six items. 
Also, why have you chosen 51? How does that relate to anything?
More Answers (0)
See Also
Categories
				Find more on Code Generation 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!
