Plot a for loop but it doesn't show all the curves on my graph

2 vues (au cours des 30 derniers jours)
Tsang Chak Ng
Tsang Chak Ng le 16 Déc 2017
Hi I am try to plot a loop function as following,but for some reason the graph doesn't show all the ten curves.What have I done wrong? Commands: clear all k=3; stimulus=[1:100] hold on; for a=1:10 modelS=k*(stimulus.^a); plot(stimulus,modelS) end hold off;
  1 commentaire
Are Mjaavatten
Are Mjaavatten le 16 Déc 2017
Your script does indeed plot 10 curves, but the last one has such a high maximum value that the other curves almost disappear. Try semilogy instead. You must modify your loop somewhat, since it seems that you cannot define logarithmic axes after the hold command:
k=3;
stimulus=[1:100];
figure;
for a=1:10
modelS=k*(stimulus.^a);
semilogy(stimulus,modelS);
hold on;
end
hold off;

Connectez-vous pour commenter.

Réponses (1)

Star Strider
Star Strider le 16 Déc 2017
Try this:
k=3;
stimulus = 1:100;
hold on;
for a=1:10
modelS=k*(stimulus.^a);
plot(stimulus,modelS, 'p')
end
hold off
or this:
k=3;
stimulus = 1:100;
a=1:10;
modelS = k*bsxfun(@power, stimulus', a);
plot(stimulus, modelS)
MATLAB plots a line by default, requiring at least two coordinates. So if you plot in a loop, plot a marker instead.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by