Code covered by the BSD License  

Highlights from
Naming figures (fig.m)

image thumbnail
from Naming figures (fig.m) by Aslak Grinsted
Create new figures with a windowtitle.

H=fig(varargin)
function H=fig(varargin)
% H=fig([name/number][,figureproperties])
%
% This function works just like the figure command in MATLAB except that you
% reference figures by names instead of figure handles. (you can still use
% the handles though)
%
% fig('Randfig')
% plot(randn(10,1))
% fig('fig 2')
%surf(peaks)
% fig('Randfig')
%
% fig('My figure','renderer','opengl');
%
% note that the fig command will by default set numbertitle=off. 
%
% (c) Aslak Grinsted 2010
%

figs=get(0,'children');

if length(varargin)>0
    if ischar(varargin{1})
        sName=varargin{1};
        figs=figs(find(strcmp(get(figs,'type'),'figure')));
        figs=figs(find(strcmp(get(figs,'name'),sName)));
        if length(figs)>0
            H=figure(figs(1));
        else
            H=figure;
        end
        set(H,'name',sName);
    else
        sName='';
        number=varargin{1};
        H=figure(varargin{1});
        set(H,'name',['Fig ' num2str(H)]);
    end
else
    H=figure;    set(H,'name',['Fig ' num2str(H)]);
end

if ~any(figs==H)
    set(H,'NumberTitle','off');
end
if length(varargin)>1
    set(H,varargin{2:end});
end


if nargout==0
    clear H
end

Contact us