MATLAB: Plotting with a for loop

MATLABplotting

I have a for loop and need to plot my final results. I have the hold on command in my code, but I still get only one point on my plot. What am I doing wrong?

Best Answer

You probably have the plot command inside your loop.
Guessing as to your code, but it is best to do something like this instead :
for k = 1:n
x(k) = k;
y(k) = sin(x(k));
end
figure(1)
plot(x, y)
Related Question