-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreusefig.m
55 lines (52 loc) · 2.28 KB
/
reusefig.m
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
function [FigOH,Exists] = reusefig(TagName,varargin)
%reusefig Creates and/or re-uses a figure with specific tag
%
% [FigOH,Exists] = reusefig(TagName,'PropName1',PropVal1,'PropName2',PropVal2,...)
%
% Looks for the figure with tag 'TagName' and makes it current, or
% creates it if necessary. Returns the handle 'FigOH' of the figure.
%
% This function can be used in order to re-use the same plot windows
% for several calls of the same plotting routine (avoids creating new
% figures at every call or plotting in windows "belonging" to other
% functions).
%
% A list of arguments pairs can be passed on to this function which will
% use them to set the various properties of the figure (see SET).
%
% The function returns Exists=1 if the figure already existed before, 0 if
% it had to create a new figure.
% Release date: August 2008
% Author: Eric A. Lehmann, Perth, Australia (www.eric-lehmann.com)
%
% Copyright (C) 2008 Eric A. Lehmann
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
FigOH = findobj('type','figure','tag',TagName);
if isempty(FigOH),
% Create a new figure if no exisiting one found:
FigOH = figure('tag',TagName,'IntegerHandle','off','NumberTitle','off','Name',TagName,varargin{:});
% Uses non-integer handle to reduce the probability of other functions inadvertently
% plotting into it (which is why the function reusefig is done for!).
Exists = 0;
elseif isequal(size(FigOH),[1 1]),
figure(FigOH); % If already existing, makes it current and brings it to screen.
if ~isempty(varargin),
set(FigOH,varargin{:}); % Set figure properties to desired user values.
end
Exists = 1;
%shg;
else
error('More than one object found with same tag!');
end