You do not need those three nested for loops: you calculate the same thing in every iteration of the loop. You can just use
X = l1 * cos(THETA1) + l2 * cos(THETA1+THETA2) + l3 * cos(THETA1+THETA2+THETA3);
Y = l1 * sin(THETA1) + l2 * sin(THETA1+THETA2) + l3 * sin(THETA1+THETA2+THETA3);
with no loops.
But then you end up with X and Y both three dimensional; what it means to plot that is not well defined. But you could try
X1 = reshape(X, size(X,1), size(X,2)*size(X,3));
Y1 = reshape(Y, size(Y,1), size(Y,2)*size(Y,3));
plot(X1, Y1)
Best Answer