for循环中没有可见点 [英] No visible points for plot in for loop

查看:56
本文介绍了for循环中没有可见点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为要使用for循环制作的图而苦苦挣扎.

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.

推荐答案

您需要指定一个标记.文档说:

You need to specify a marker. The documentation says:

如果 X Y 中的一个是标量,另一个是标量或向量,则plot函数将绘制离散点.但是,要查看这些点,必须指定标记符号,例如 plot(X,Y,'o')

If one of X or Y 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')

它将是:

plot(k,fib(k),'o');


还请注意,您正在创建一个10维数组,其中包含 fib = ones(1:10); .您很可能打算在 1 到 10 之间写一个逗号而不是冒号来创建行向量.即


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);

或列向量为 HansHirse 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆