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
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
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!