Skip to content

Commit 07ba84e

Browse files
author
Cove Sturtevant
committed
Add files via upload
Part 5
1 parent 38f79b9 commit 07ba84e

28 files changed

Lines changed: 3723 additions & 0 deletions
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
function hout=suptitle(str)
2+
%SUPTITLE Puts a title above all subplots.
3+
% SUPTITLE('text') adds text to the top of the figure
4+
% above all subplots (a "super title"). Use this function
5+
% after all subplot commands.
6+
7+
% Drea Thomas 6/15/95 drea@mathworks.com
8+
9+
% Warning: If the figure or axis units are non-default, this
10+
% will break.
11+
12+
% Parameters used to position the supertitle.
13+
14+
% Amount of the figure window devoted to subplots
15+
plotregion = .88;
16+
% plotregion = .75;
17+
18+
% Y position of title in normalized coordinates
19+
% titleypos = .95;
20+
titleypos = .97;
21+
22+
23+
% Fontsize for supertitle
24+
% fs = get(gcf,'defaultaxesfontsize')+4;
25+
fs = get(gcf,'defaultaxesfontsize');
26+
27+
% Fudge factor to adjust y spacing between subplots
28+
fudge=1;
29+
30+
haold = gca;
31+
figunits = get(gcf,'units');
32+
33+
% Get the (approximate) difference between full height (plot + title
34+
% + xlabel) and bounding rectangle.
35+
36+
if (~strcmp(figunits,'pixels')),
37+
set(gcf,'units','pixels');
38+
pos = get(gcf,'position');
39+
set(gcf,'units',figunits);
40+
else,
41+
pos = get(gcf,'position');
42+
end
43+
ff = (fs-4)*1.27*5/pos(4)*fudge;
44+
45+
% The 5 here reflects about 3 characters of height below
46+
% an axis and 2 above. 1.27 is pixels per point.
47+
48+
% Determine the bounding rectange for all the plots
49+
50+
% h = findobj('Type','axes');
51+
52+
% findobj is a 4.2 thing.. if you don't have 4.2 comment out
53+
% the next line and uncomment the following block.
54+
55+
h = findobj(gcf,'Type','axes'); % Change suggested by Stacy J. Hills
56+
57+
% If you don't have 4.2, use this code instead
58+
%ch = get(gcf,'children');
59+
%h=[];
60+
%for i=1:length(ch),
61+
% if strcmp(get(ch(i),'type'),'axes'),
62+
% h=[h,ch(i)];
63+
% end
64+
%end
65+
66+
67+
68+
69+
max_y=0;
70+
min_y=1;
71+
72+
oldtitle =0;
73+
for i=1:length(h),
74+
if (~strcmp(get(h(i),'Tag'),'suptitle')),
75+
pos=get(h(i),'pos');
76+
if (pos(2) < min_y), min_y=pos(2)-ff/5*3;end;
77+
if (pos(4)+pos(2) > max_y), max_y=pos(4)+pos(2)+ff/5*2;end;
78+
else,
79+
oldtitle = h(i);
80+
end
81+
end
82+
83+
if max_y > plotregion,
84+
scale = (plotregion-min_y)/(max_y-min_y);
85+
for i=1:length(h),
86+
pos = get(h(i),'position');
87+
pos(2) = (pos(2)-min_y)*scale+min_y;
88+
pos(4) = pos(4)*scale-(1-scale)*ff/5*3;
89+
set(h(i),'position',pos);
90+
end
91+
end
92+
93+
np = get(gcf,'nextplot');
94+
set(gcf,'nextplot','add');
95+
if (oldtitle),
96+
delete(oldtitle);
97+
end
98+
ha=axes('pos',[0 1 1 1],'visible','off','Tag','suptitle');
99+
ht=text(.5,titleypos-1,str);set(ht,'horizontalalignment','center','fontsize',fs);
100+
set(ht, 'Tag', 'Suptitle');
101+
set(gcf,'nextplot',np);
102+
% axes(haold);
103+
set(gcf, 'CurrentAxes', haold);
104+
if nargout,
105+
hout=ht;
106+
end
107+
108+
109+
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
function [err] = argterr(func, arg, datatypes, arg_size, mode, msg, return_type)
2+
% argterr - Check the data type and size of a function argument.
3+
%
4+
%****f* wmtsa.utils/argterr
5+
%
6+
% NAME
7+
% argterr - Check the data type and size of a function argument.
8+
%
9+
% SYNOPSIS
10+
% [errmsg] = argterr(func, arg, type, [arg_size], [mode])
11+
% [errmsg] = argterr(func, arg, type, [arg_size], [mode], [msg], 'string')
12+
% [errstruct] = argterr(func, arg, type, [arg_size], [mode], [msg], 'struct')
13+
%
14+
% INPUTS
15+
% * func -- checked function (string or function handle).
16+
% * arg -- the argument to check (object)
17+
% * datatypes -- expected data type(s) of the arg.
18+
% See verify_datatypes function for possibles datatypes to check.
19+
% (string or string cell array).
20+
% * arg_size -- (optional) expected size of array (integer vector).
21+
% * mode -- (optional) output display mode (charcter string)
22+
% * msg -- (optional) message string to be displayed (string).
23+
% * return_type -- (optional) type of output argument (string).
24+
% 'string' = return error message string (default).
25+
% 'struct' = return error message struct.
26+
%
27+
% OUTPUTS
28+
% * errmsg -- error message (string).
29+
% * errstruct -- error struct with fields: message, identifier.
30+
%
31+
% SIDE EFFECTS
32+
% Function call requires a minimum of three input arguments; otherwise error.
33+
%
34+
% DESCRIPTION
35+
% argterr checks the data type(s) and optionally the size of an argument to a
36+
% function call. If arg does not have the specified data type(s), an error
37+
% message or error struct is returned.
38+
%
39+
% arg may be a single
40+
%
41+
% Possible values for 'datatypes' to check include:
42+
% * 'posint' -- All are positive integers --> integer value(s) > 0.
43+
% * 'int0' -- All are positive integers plus zero --> integer value(s) >= 0.
44+
% * 'int','integer' -- All are integers --> any integer value(s).
45+
% * 'num','numeric' -- All are numeric.
46+
% * 'struct','structure' -- Is a structure.
47+
% * 'char','character','string' - Is a character string.
48+
% * 'scalar -- Is a point (size of all dimensions = 1).
49+
% * 'vec','vector' -- Is a vector (i.e. MxN, with M and/or N = 1).
50+
% * 'nonsingleton','truevector' -- Is a vector (i.e. MxN with M *or* N = 1).
51+
% * 'row','rowvector' -- Is a row vector (i.e. M x 1).
52+
% * 'col','columnvector' -- Is a column vector (i.e. 1 x N).
53+
% * 'finite' -- All are finite.
54+
% * 'nonsparse' -- Is a non-sparse matrix.
55+
%
56+
% The input argument 'mode' controls the display of diagnostic information
57+
% to the consolue and has possible values:
58+
% * 0 -- silent
59+
% * 1 -- verbose
60+
% The default value is 1 (silent).
61+
%
62+
% EXAMPLE
63+
% arg = [0 2];
64+
% % arg is an integer.
65+
% err = argterr('myfunction', arg, 'posint')
66+
% % Result: err = 1
67+
% err = argterr('myfunction', arg, 'int', [1 2], '')
68+
% % Result: err = 0
69+
% [err, errmsg] = argterr('myfunction', arg, {'int', 'vector'})
70+
% % Result: err = 0
71+
%
72+
% NOTES
73+
% argterr is modelled after errargt, which is part of MATLAB wavelet toolkit.
74+
%
75+
% SEE ALSO
76+
% verify_datatype
77+
%
78+
79+
% AUTHOR
80+
% Charlie Cornish
81+
%
82+
% CREATION DATE
83+
% 2003-06-22
84+
%
85+
% COPYRIGHT
86+
% (c) 2003, 2004, 2005 Charles R. Cornish
87+
%
88+
% CREDITS
89+
% argterr is inspired by the function errargt
90+
% by M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi
91+
% which is part of the MATLAB wavelet toolkit.
92+
%
93+
% MATLAB VERSION
94+
% 7.0
95+
%
96+
% REVISION
97+
% $Revision: 612 $
98+
%
99+
%***
100+
101+
% $Id: argterr.m 612 2005-10-28 21:42:24Z ccornish $
102+
103+
%% Set Defaults
104+
err = [];
105+
valid_mode = [0 1];
106+
valid_return_type = {'string', 'struct'};
107+
108+
usage_str = ['Usage: [err, errmsg] = ', mfilename, ...
109+
'(func, arg, datatypes, [arg_size], [mode], [msg], [return_type])'];
110+
111+
%% Check arguments
112+
error(nargerr(mfilename, nargin, [3:7], nargout, [0:1], ...
113+
1, usage_str, 'struct'));
114+
115+
if (ischar(func))
116+
funcname = func;
117+
elseif (isa(func, 'function_handle'))
118+
funcname = func2str(func);
119+
else
120+
error('WMTSA:nargerr:invalidInputArgumentValue', ...
121+
'func must be a string or function handle');
122+
end
123+
124+
arg_name = inputname(2);
125+
126+
if (iscellstr(datatypes))
127+
% OK - do nothing
128+
elseif (ischar(datatypes))
129+
% Convert to character cell array.
130+
datatypes = {datatypes};
131+
else
132+
error('WMTSA:invalidArgumentType', ...
133+
['Argument ''datatypes'' must be a charcter string or charcter cell ' ...
134+
'array.']);
135+
end
136+
137+
if (~exist('mode', 'var'))
138+
mode = 1;
139+
end
140+
141+
if (isempty(find(mode == valid_mode)))
142+
err_s.message = ['Invalid value for input argument ', 'mode'];
143+
err_s.identifier = ['WMTSA:nargerr:invalidInputArgumentValue'];
144+
error(err_s);
145+
end
146+
147+
if (~exist('return_type', 'var') || isempty(return_type))
148+
return_type = 'string';
149+
end
150+
151+
if (isempty(strmatch(return_type, valid_return_type)))
152+
err_s.message = ['Invalid value for input argument ', 'return_type'];
153+
err_s.identifier = ['WMTSA:nargerr:invalidInputArgumentValue'];
154+
error(err_s);
155+
end
156+
157+
% Check argument datatypes
158+
[tf, errmsg] = verify_datatype(arg, datatypes, arg_name);
159+
160+
err_s = [];
161+
162+
if (~tf)
163+
err_s.identifier = ['WMTSA:argterr:invalidArgumentDataType'];
164+
err_s.message = errmsg;
165+
else
166+
% Check argument dimension sizes
167+
if (exist('arg_size', 'var') && ~isempty(arg_size))
168+
actual_arg_size = size(arg);
169+
if (~isequal(actual_arg_size, arg_size))
170+
err_s.identifier = ['WMTSA:argterr:incorrectArgumentDimensions'];
171+
err_s.message = ['Expected and actual sizes of ', arg_name, ' are not equal'];
172+
end
173+
end
174+
end
175+
176+
if (~isempty(err_s))
177+
178+
if (mode)
179+
display_errmsg(funcname, err_s.message)
180+
end
181+
182+
if(exist('msg', 'var'))
183+
disp(msg);
184+
end
185+
186+
if (strmatch(return_type, 'string'))
187+
err = err_s.message;
188+
elseif (strmatch(return_type, 'struct'))
189+
err = err_s;
190+
end
191+
end
192+
193+
194+
return
195+
196+
197+
function display_errmsg(funcname, errmsg)
198+
199+
blank = ' ';
200+
201+
if (~isempty(deblank(funcname)))
202+
msg = [' ', funcname, ': ', xlate(errmsg)];
203+
else
204+
msg = errmsg;
205+
end
206+
207+
msg_length = length(msg);
208+
banner_length = msg_length + 2;
209+
star_str = '*';
210+
star_str = star_str(:, ones(1, banner_length));
211+
minus_str = '-';
212+
minus_str = minus_str(:, ones(1, banner_length));
213+
214+
215+
disp(blank);
216+
disp(star_str);
217+
disp('ARGUMENT TYPE ERROR ...');
218+
disp(minus_str);
219+
disp(msg);
220+
disp(star_str);
221+
disp(blank);
222+
223+
return
224+
225+
226+

0 commit comments

Comments
 (0)