-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfigurec.m
47 lines (46 loc) · 1.51 KB
/
figurec.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
% FROM:
% http://www.mathworks.com/matlabcentral/fileexchange/8670-create-non-overlapping-cascading-figure-windows
%
% FIGUREC - create a figure window in a non-overlapping (cascading)
% location
%
% USAGE:
%
% figurec
% figurec(...)
% h=figurec
% h=figurec(...)
%
% FIGUREC acts just like the Matlab FIGURE command, with all arguments
% passed through, except that the new figure is created a little to the
% right and down from the highest numbered figure currently existing, so
% that they won't overlap. If moving the location would push the figure too
% close to the edge of the screen, then the new figure is created in the
% default location as usual. (Subsequent figures will again be cascaded.)
%
% EXAMPLE:
%
% close all;for n=1:20;figurec('color',rand(1,3));plot(0,0);title('Sample');end
function varargout=figurec(varargin)
f = findobj(0,'type','figure'); % list of existing figures
ss=get(0,'ScreenSize'); % pixel size of entire screen
h=figure(varargin{:}); % create figure using pass-through arguments
hp = get(h,'pos'); % size of new figure when created
if ~isempty(f)
f=max(f);
u=get(f,'units');
set(f,'units','pixels')
p=get(max(f),'pos');
set(f,'units',u)
% if moving won't push too far, move; else leave in default location
if p(1)+50+hp(3) <= ss(3) & p(2) >= 5
u=get(h,'units');
ss = get(0,'screensize');
set(h,'units','pixels')
set(h,'pos',[p(1)+50 p(2)-50 hp(3:4)]);
set(h,'units',u)
end
end
if nargout > 0
varargout{1}=h;
end