I wonder why these two code doesn’t produce the same plot?
code 1:
x=[2,5,7];
y=[10,4,3];
plot(x,y);
code 2:
x=[2,5,7];
y=[10,4,3];
for i=1:length(x)
xx=x(i);
yy=y(i);
plot(xx,yy);
end
EDITED:
How I can make the output of Code 2 similar to output in Code 1
Code 1
You’re drawing a line with the
xandycoordinates defined in the vectors with theplot(x,y)command. By default, it meansplot(x,y,'-');which means you draw a line (-).Code 2
You’re drawing individual points (no line) stored in the vectors since you’re calling
plotfor each point (xx,yy)You can duplicate the effect in Code 2 in Code 1, with the following change:
This forces MATLAB to only plot the points and not the connecting line
If you want the points and the line,
For more details, check out the documentation of the
plotcommand.Sample Code: