Finds and activates, or creates, figure with user-specified name.
If no name is provided, creates figure named "untitledn" (where n is incremented to result in a unique name).
If figure named 'My Figure' exists, it will be activated (brought to the front and shown). Otherwise, it will be created.
h = togglefig('My Figure');
Also returns the handle to the specified or created figure.
Creates and activates new figure named untitled1, untitled2, ...
Note: You can subsequently activate these figures with, for instance, togglefig('untitled1').
NOTE: This example requires the Image Processing Toolbox
im = imread('cameraman.tif');
for ii = 1:10
thresh = ii/20;
title(sprintf('Threshold = %0.2f',thresh));
I've found this to be exceptionally useful in algorith-development
mode, particularly when iterating on cells in the cell-mode editor. (I
use this function in almost every mfile I write these days.)
Great idea and nice implementation !!!! I've just downloaded and I'm already loving it... :-)
Just a small bug found, when called without any arguments, I get:
??? Input argument "clearfig" is undefined.
The problem is solved by adding the line
clearfig = 0;
elseif nargin == 1
17 Oct 2008
victor de lafuente
Thanks for this useful function.
I suggest a couple of extra lines to generate a unique figure number, so that other *.m files still using figure(1), figure(2), etc. do not overwrite the figures created by togglefig. It will pause for 10 ms each time a new figure is created, but this can be modified according to your computer platform (see 'pause' help).
ALL: To further follow up on John's comment, note that John correctly pointed out (via private email) that suppressing the handle if nargout == 0 does not disallow the reference-by-name functionality I wanted. I'm reposting the file to implement the modest change he suggested.
10 Jan 2008
Thanks for the comment, John. My first thought was to implement your suggestion; it would be trivially easy. But on reflection, I like TOGGLEFIG's forced issuance of a handle. In my workflow, I do things like:
This gives me painless (by-name) handling of my figures, and frees me from having to use the more unwieldy