Plot a for loop but it doesn't show all the curves on my graph
2 views (last 30 days)
Show older comments
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 Comment
Are Mjaavatten
on 16 Dec 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;
Answers (1)
Star Strider
on 16 Dec 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.
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!