Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
How to begin with multiple graphs of 'y(x+1)=y(x)+0.02*randn;' from x=1? i.e. 10 graphs?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
a=0;
b=100;
c=0;
y=a+(b-a).*rand;
for x=1:365
y(x+1)=y(x)+0.02*randn;
if y(x+1)>100
y(x+1)=y(x)
else if y(x+1)<0
c=c+1
break
end
plot(y)
c
end
end
0 comentarios
Respuestas (1)
Chris Perkins
el 17 de Nov. de 2017
Hi Karolina,
If I understand your question correctly, you want multiple graphs created, and then to plot your function on all of them.
You can create multiple figures, and store a handle to the axes for each, you can then later use that axes handle to plot on the graph of that specific figure.
Here's your code, with a few lines that I have added to show how you can accomplish this:
a=0;
b=100;
c=0;
y=a+(b-a).*rand;
% Added Code
axisHandles = [];
for i=1:10
figure
axisHandles(i) = gca;
end
% End Added Code
for x=1:365
y(x+1)=y(x)+0.02*randn;
if y(x+1)>100
y(x+1)=y(x)
else if y(x+1)<0
c=c+1
break
end
% Adjusted Code
for i=1:10
plot(axisHandles(i),y);
end
% End Adjusted Code
c
end
end
If you wanted different plots on each graph, you can change the second section of added code to plot a different function on each graph.
Alternatively, if you wanted all of these graphs in the same figure, you could use the "subplot" command, as described in the following documentation page:
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!