Trying to graph each iteration of the for loop

1 view (last 30 days)
I have a ode45 set up and want to graph multiple values on the same graph, how do I do it? I thought about using a for loop and iterating through then using hold on every iteration but it is not working, anyone help?
code:
clear all
t0=0;
tf=365*20;
p0=[100, 1, 0, 2500, 1, 0];
tspan=[t0,tf];
[t,p]=ode45(@vectorf,tspan,p0);
gammaM=[0 0.01 0.06 0.12 0.144];
ode part:
for i=gammaM
pdot(1,:)=rM.*(p(1)+p(2)+p(3)) - muM.*p(1)- betaM.*p(1).*p(5) - i.*p(1);
plot(t,p(1,:))
hold on
end
hold off
I want it to graph all of those values on 5 different lines on the same graph, please help.
  1 Comment
Tamir Suliman
Tamir Suliman on 1 Dec 2016
what is vectorrf ? Undefined function or variable 'vectorf'.
Please format the post using the proper options to display your code

Sign in to comment.

Answers (1)

James Tursa
James Tursa on 1 Dec 2016
You are plotting p(1,:) in the loop, but this never changes in the loop. Did you mean to plot pdot instead? E.g.,
plot(t,pdot(1,:))

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!