Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Evan
Evan am 17 Mär. 2014
Beantwortet: Marta Salas am 18 Mär. 2014
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.

Akzeptierte Antwort

Marta Salas
Marta Salas am 18 Mär. 2014
figure
hold on
for ...
plot ...
end
title
xlabel
ylabel

Weitere Antworten (1)

Jacques
Jacques am 18 Mär. 2014
Try to use hold instead of figure

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by