MATLAB: Plot the result of a for loop.

plot for loop

I'm trying to plot the result of this for loop but I only get the first point for the counter j=1. Can anyone tell me what's wrong?
teta = (0:1:360)*pi/180;
for j = 1:1:nd
teta_j = teta(j);
gamma_j = pi - asin(lambda.*sin(teta_j));
X_cv2_j = X_cv2(j);
Y_cv2_j = Y_cv2(j);
T_FL = [cos(pi+gamma_j) -sin(pi+gamma_j) r*cos(teta_j); % Matrice locale --> fissa
sin(pi+gamma_j) cos(pi+gamma_j) r*sin(teta_j);
0 0 1 ];
T_LF = inv(T_FL); % Matrice fissa --> locale
C_IRF = [X_cv2_j; Y_cv2_j; 1]; % Matrice punti polare fissa
C_IRL1 = T_LF*C_IRF;
C_IRL = C_IRL1(1:2, 1);
C_IRL_X = C_IRL(1) % Coordinata X polare mobile

C_IRL_Y = C_IRL(2) % Coordinata X polare mobile
plot(C_IRL_X, C_IRL_Y)
end

Best Answer

I can’t run your code.
I would index them, and put the plot call outside the loop:
... CODE ...
C_IRL_X(j) = C_IRL(1); % Coordinata X polare mobile

C_IRL_Y(j) = C_IRL(2); % Coordinata X polare mobile
end
plot(C_IRL_X, C_IRL_Y)