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

2 次查看(过去 30 天)
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 个评论
Are Mjaavatten
Are Mjaavatten 2017-12-16
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;

请先登录,再进行评论。

回答(1 个)

Star Strider
Star Strider 2017-12-16
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.

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by