Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
How to begin with multiple graphs of 'y(x+1)=y(x)+0.02*randn;' from x=1? i.e. 10 graphs?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Chris Perkins
2017년 11월 17일
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:
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!