Plot a for loop but it doesn't show all the curves on my graph
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Are Mjaavatten
el 16 de Dic. de 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;
Respuestas (1)
Star Strider
el 16 de Dic. de 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 comentarios
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!