how to plot points in a loop?

for x=1:10
a=2*x
b=3*x^2
plot(a,b)
end
But the figure cannot be plotted. What should i write for the codes?

1 件のコメント

Stephen23
Stephen23 2018 年 3 月 1 日
@Chen Ji: do you want the points to be joined by a line?

サインインしてコメントする。

回答 (1 件)

Stephen23
Stephen23 2018 年 3 月 1 日
編集済み: Stephen23 2018 年 3 月 1 日

0 投票

figure()
hold on
for ...
...
plot(a,b,'*')
end
But I would not recommend doing this: the simpler MATLAB solution would be to write vectorized code:
X = 1:10;
A = 2*X;
B = 3*X.^2;
plot(A,B,'-*')

1 件のコメント

Austin Selvog
Austin Selvog 2020 年 10 月 29 日
This also does not work

サインインしてコメントする。

タグ

質問済み:

2018 年 3 月 1 日

コメント済み:

2020 年 10 月 29 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by