MATLAB Answers


Why doesn't "hold on" work when I have a figure that has opened with the title bar Figures - Figure 1?

Asked by K
on 24 Apr 2014
Latest activity Commented on by K
on 24 Apr 2014
Normally, I can make a plot and save it as a .fig file. Then, when I open it later, it will open and show just "Figure 1" in the title bar. Then I can use the command "hold on" to plot other things on that same graph.
On a few of my recent graphs, I had to open the Figure Properties to change some line sizes and I saved those figures in the same way. Now, when I open those figures, the title bar says "Figures - Figure 1" and when I use hold on, it makes a new graph.
It seems like I must have somehow opened these differently somehow, but I have no idea why hold on wouldn't work in the same way, or what I did. Can anyone offer an idea of how to get my figures to open up as JUST the single figure so that I can use hold again?
Thank you!


Sign in to comment.

1 Answer

Answer by Walter Roberson
on 24 Apr 2014
 Accepted Answer

"hold on" applies to the current axis. Possibly the axis that is current at the time you do the "hold on" is not the one you expect. You can hold a specific axis if you use the function form. For example,
hold( find(gcf, 'tag', 'MyGui_axes1'), 'on')


I'm not sure, although I did find what makes it work, versus not work. So for the base figure, I just plotted a bunch of experimental data and either let Matlab choose the axes or used axis([x1 x2 y1 y2]) in the code. Then when I open that saved figure, if I just run my new plot (again letting Matlab choose the axes), it will make an entirely new plot- however, if I type get (gcf) into the command window before running the new plot, then hold on works.
Also, if I use hold( findobj(gcf, 'tag', 'MyGui_axes1'), 'on') , I get the following error:
Error using ==> hold Unknown command option.
So like I said, I can use the get(gcf) workaround, but its a bit of a pain, so if you have a better idea, maybe let me know? Thanks!
Ooh, but I can put the get(gcf) in the m file and that seems to work, so that's an ok solution for the time-being. Strange that it won't just find the single open figure without that. Thanks again for all of your help! You guys are the best about helping with this kind of stuff.

Sign in to comment.