-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcpsFindFig.m
More file actions
73 lines (67 loc) · 2.45 KB
/
cpsFindFig.m
File metadata and controls
73 lines (67 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
function [h,created] = cpsFindFig(tag,varargin)
%cpsFindFig Create or find a figure-window by name.
% cpsFindFig(TAG) creates a new figure named and tagged with string
% TAG. Or, if a figure tagged with TAG already exists, brings it into
% focus.
%
% cpsFindFig(...,'clf') additionallly clears the window.
%
% cpsFindFig takes these optional parameter-value pairs:
% Parameter Value (default in brackets):
% 'visible' Figure visibility upon creation [true] | false
% 'position' Figure position in pixels [leftx topy wid hei],
% or an empty array ([], the default) which produces
% a standard-size window.
% 'create' Toggle the creation of a new figure when a novel
% TAG is provided [true] | false.
%
% [H,CREATED] = cpsFindFig(...) Returns the figures's class object H
% and a logical which indicates if a novel figure has been created or
% not.
%
% Part of <a href="matlab:help cpsPlotTools">cpsPlotTools</a>.
%
% See also: figure
% Copyright 1998 Bart Krekelberg, 2016 Jacob Duijnhouwer
if nargin==0
error('Not enough input arguments, a figure name is required.');
end
% see if 'clf' flag has been provided
clf_flag=contains('clf',varargin,'IgnoreCase',true);
varargin(clf_flag)=[];
clf_flag=any(clf_flag);
p=inputParser;
p.addRequired('tag',@ischar);
p.addParameter('visible',true,@islogical);
p.addParameter('position',[],@(x)isempty(x) || isnumeric(x) && numel(x)==4);
p.addParameter('create',true,@(x)islogical(x) || x==1 || x==0);
p.parse(tag,varargin{:});
if p.Results.visible
visi='on';
else
visi='off';
end
h = findobj(get(0,'children'),'flat','tag',tag);
if ~isempty(h)
% set focus to already existing figure
set(h,'visible',visi);
figure(h);
created=false;
elseif p.Results.create
h = figure('visible','off');
set(h,'resize','on','tag',tag,...
'visible','off','name',tag,'menubar','figure',...
'numbertitle','off',...
'paperunits','centimeters');
drawnow;
set(h,'visible',visi);
created=true;
else
h=[];
created=false;
return;
end
if ~isempty(p.Results.position)
set(h,'Position',p.Results.position);
end
end