How to plot multiple iterations of a for loop on the same axes.

조회 수: 3 (최근 30일)
Evan
Evan 2014년 3월 17일
답변: Marta Salas 2014년 3월 18일
Using the ode45 function I am analyzing a set of two ODEs varying one of the inputs from 1 to 9 in steps of 2. I then want to plot the phase plan generated by each iteration on the same set of axes, in a different colour.
My script:
for i=1:2:9
[t,y]=ode45(@predprey2,[0,30],[i,1]);
figure
plot(y(:,1),y(:,2));
title('Phase plane of prey and predator populations');
xlabel('Prey Population');
ylabel('Predator Population');
end
and the called function (predprey2.m):
function output=predprey2(t,y)
dxdt=y(1)-y(1)*y(2);
dwdt=y(1)*y(2)-y(2);
output=[dxdt; dwdt];
end
Any and all help is appreciated.
  댓글 수: 1
Jan
Jan 2014년 3월 17일
You forgot to ask a question. What is the point you need help for?

댓글을 달려면 로그인하십시오.

채택된 답변

Marta Salas
Marta Salas 2014년 3월 18일
figure
hold on
for ...
plot ...
end
title
xlabel
ylabel

추가 답변 (1개)

Jacques
Jacques 2014년 3월 18일
Try to use hold instead of figure

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by