Some of you may be familiar with my own togglefig function; it allows one to recall and reuse a figure by specifying its name. I find it extremely practical, and I use it almost on a daily basis. (It's particularly useful when you're iterating on a block of code separated into "sections." Andrew's setname makes a very nice companion to togglefig.)
As of this writing, Andrew has 10 files on the Exchange, which have collectively been downloaded more than 500 times in the past 30 days. (Not too shabby!) Nonetheless, I don't believe any of his submissions have previously been recognized as a Pick of the Week. Until now.
Ironically, the file of Andrew's that I am most enamored of is his least-downloaded.
So what does Andrew's function do? If you've previously indicated a title for the axes in your figure, setname automatically renames the figure to match axes name. If you haven't titled your graphic, the function extracts a string from the x- and y- labels of the axes to construct a figure name.
Consider, for example, this snippet of code:
t = 0:pi/64:8*pi; plot(t,sin(t)+rand(size(t))) xlabel('Time') ylabel('Noisy Sine') title('Noisy Sinusoid')
This creates a figure not-so-usefully named "Untitled" (with a number appended to differentiate it from the other n "Untitled" figures you've previously created.)
Now issue the setname command (no arguments needed--it works by default on the current axes, though you may specify a non-default axes.) Now the figure is renamed to "Noisy Sinusoid," and you can readily pick it out from all the other open figures.
Alternatively, if you didn't explicitly provide a title, setname would automatically name the figure "Time vs Noisy Sine." Now not only can I find the figure, I can easily reuse it:
% Recall the previous figure... togglefig('Noisy Sinusoid') plot(t,cos(t)+rand(size(t))) title('Noisy Cosine') % ...and then rename the figure! setname
This is brilliant, Andrew...thanks! One suggestion: it would be really nice if I could pass to setname an argument ('all'?) that tells the function to rename all open figures. (For those times when I've lazily created 20 different 'Untitled' figures.)
コメントを残すには、ここ をクリックして MathWorks アカウントにサインインするか新しい MathWorks アカウントを作成します。