Hold on command for ode45 plot

1 view (last 30 days)
Lorenzo
Lorenzo on 30 Dec 2014
Commented: Lorenzo on 30 Dec 2014
Hi everybody! I am doing some exercises on solving systems of differential equations. I wanted to plot many solution curves on the same figure so I made a for loop:
for i=0:6
[t, x] = ode45(@exc_345, [-4 4], [-i i]);
hold on
plot(x(:,1),x(:,2));
hold off
end
It worked but now I saw that it is not "correct": the hold on and hold off commands would have to be out of the loop. Why does it work anyway? Thanks.

Accepted Answer

Jan
Jan on 30 Dec 2014
The hold off is overridden by the following hold on. So you can omit the hold off. The repeated call of hold on does not matter also, because the main action is that the 'NextPlot' property of the current plot is set to 'add'. Doing this repeatedly is not a problem.
  1 Comment
Lorenzo
Lorenzo on 30 Dec 2014
Thank you very much! I did not know much about the hold on/off properties.

Sign in to comment.

More Answers (0)

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!