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*ra​ndn;' from x=1? i.e. 10 graphs?

1 visualización (últimos 30 días)
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

Respuestas (1)

Chris Perkins
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:
  2 comentarios
Karolina
Karolina el 19 de Nov. de 2017
I apologize for asking unclearly, I wasn't sure how to put this into words. I mean to ask, how to plot ten different results on same figure?
Karolina
Karolina el 19 de Nov. de 2017
Here is what I tried but doesn't seem to work
a=0;
b=100;
c=0;
y_i=a+(b-a).*rand;
for i=1:10
for x=1:365
y_i(x+1)=y_i(x)+0.02*randn;
if y_i(x+1)>100
y_i(x+1)=y_i(x)
else if y_i(x+1)<0
c=c+1
break
end
plot(y_i)
end
end
end

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by