Why is "hold all" not working in this instance?
Afficher commentaires plus anciens
Hi All,
I have attached a project I am working on at the moment. I want to hold any plots I create (currently two) at the end of a while loop, so that when the user choses to run the program again (and repeat the loop) the previous plots are held for comparison.
I have tried hold on, and hold all on line 396 where I specify what to do if the user wants to re-run the simulation and hold the plots.
I have also tried commenting out the clear variables command (and providing exclusions) at the start of the while loop, to no avail, thinking that clearvars was clearing the hold setting.
Leaving hold on on line 15 seems to have the desired effect, but gives an immediate blank plot on screen which I do not want on first run. I added a for loop to close all if the loop run-counter == 1 but this prevents new plots being plotted on the original axes with hold on again somehow...!
As this worked I even tried setting Hold = True at the bottom of the loop if the user wants to hold the plots, and setting 'hold on' if Hold = True at the start of the loop... as expected, didn't work.
This is driving me to insanity. Please, if you can, tell me what have I done wrong?!
I just want to hold all plots, not just the current one (which it seems to be doing unless I place the hold command in line 15) - I can't seem to find an answer to this, other than 'hold all' earlier, which i've since read achieves the same thing?
Thanks in advance,
Matt
5 commentaires
Image Analyst
le 14 Mar 2016
Post all the code we need to run it.
Undefined function or variable 'Initial_Conditions'.
Error in test3 (line 26)
Initial_Conditions;
Matt
le 14 Mar 2016
Stephen23
le 14 Mar 2016
Honestly for code this complex there are two changes you should consider, which will help you to avoid this kind of problem:
- Write functions instead of scripts!
- Call every graphics command with explicit handles (e.g. as parent, or to clear or add lines, etc).
These changes make your code mode robust, and avoid exactly the kind of errors what you are experiencing now.
Matt
le 15 Mar 2016
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!