问题
I'm struggling with a plot I want to make using a for-loop.
I know it works when I add it after the loop (just a simple plot). But I want to try it in this other way.
fib = ones(1:10);
for k=3:10
hold on
fib(k) = fib(k-1) + fib(k-2);
plot(k,fib(k))
end
hold off
The output is a plot, but there are no points visible.
回答1:
You need to specify a marker. The documentation says:
If one of
X
orY
is a scalar and the other is either a scalar or a vector, then the plot function plots discrete points. However, to see the points you must specify a marker symbol, for example,plot(X,Y,'o')
So it will be:
plot(k,fib(k),'o');
Also note that you're creating a 10-dimensional array with fib = ones(1:10);
. You most probably meant to write a comma instead of colon in between 1 and 10 to create a row vector. i.e.
fib = ones(1,10);
or a column vector as HansHirse suggested:
fib = ones(10,1);
来源:https://stackoverflow.com/questions/56166314/no-visible-points-for-plot-in-for-loop