Index exceeds the number of array elements. Please Help?
Show older comments
% Generates optimized trajectory for the robotics arm problem
function [] = generate_optimized_traj(x)
d1 = 66.04;
d3 = 14.91;
d4 = 43.31;
a2 = 43.18;
a3 = 2.03;
for i = 1:100
t = -pi + (i-1)*0.063;
theta1 = x(i);
theta2 = x(i+100);
theta3 = x(i+200);
c1 = cos(theta1);
c2 = cos(theta2);
s1 = sin(theta1);
s2 = sin(theta2);
c23 = cos(theta2+theta3);
s23 = sin(theta2+theta3);
f1(i) = c1*(a2*c2 + a3*c23 - d4*s23) - d3*s1;
f2(i) = s1*(a2*c2 + a3*c23 - d4*s23) + d3*c1;
f3(i) = d1 - a2*s2 - a3*s23 -d4*c23;
end
plot3(f1,f2,f3,'r*')
end
This is the code where the error is encountered. This appears on line 15 ( theta2=x(i+100) ).
The code above should generate the optimal trajectory for the arm of an industrial robot.
f1,f2 and f3 are kinetic equations.
Does anyone have any idea why i get the following error on line 15: Index exceeds the number of array elements (2).
Accepted Answer
More Answers (1)
Guillaume
on 21 Oct 2019
0 votes
Does anyone have any idea why i get the following error on line 15
Because the x you passed has less than 300 elements. Since i goes up to 100 and you try to access x(i+200), x needs to have at least 300 elements.
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!