how to plot points in a loop?

10 vues (au cours des 30 derniers jours)
Chen Ji
Chen Ji le 1 Mar 2018
Commenté : Austin Selvog le 29 Oct 2020
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 commentaire
Stephen23
Stephen23 le 1 Mar 2018
@Chen Ji: do you want the points to be joined by a line?

Connectez-vous pour commenter.

Réponses (1)

Stephen23
Stephen23 le 1 Mar 2018
Modifié(e) : Stephen23 le 1 Mar 2018
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 commentaire
Austin Selvog
Austin Selvog le 29 Oct 2020
This also does not work

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by