[422372]: / functions / sigprocfunc / textsc.m

Download this file

81 lines (72 with data), 2.1 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
74
75
76
77
78
79
80
% TEXTSC - places text in screen coordinates and places
% a title at the top of the figure.
%
% Usage:
% H = textsc(X,Y,TXT) places the text string, TXT
% at the normalized coordinates X and Y. H is the
% handle to the text object.
%
% H = textsc(TXT) or H = textsc(TXT,'title') or
% H = textsc('title', TXT) places a title at the top
% of the figure window. This is useful when you
% want to place a single title above multiple
% subplots.
%
% Notes: textsc creates an invisible AXES which occupies
% the entire FIGURE. The units of the AXES are
% normalized (range from 0 to 1). textsc checks
% all the children of the current FIGURE to determine
% if an AXES exist which meets these criteria already
% exist. If one does, then it places the text relative
% to that AXES.
%
% Author: John L. Galenski, January 21, 1994
% Written by John L. Galenski III
% All Rights Reserved January 21, 1994
% LDM031695jlg
function H = textsc(x,y,txt)
% Basic error checking
if nargin < 2
y = 'title';
end
if isstr(x) && strcmpi(x, 'title')
x = y;
y = 'title';
end
% Check to see if AXES already exist
ch = get(gcf,'Children');
if ~isempty(ch)
try
ind = cellfun(@(x)isequal('axes', x), get(ch, 'type'));
catch
ind = cellfun(@(x)isequal('axes', x), {get(ch, 'type')}); % fix Joe Dien bug 1538
end
if any(ind), ch = gca; end
end
ax = findobj(gcf,'Type','axes','Tag','TEXTSC');
if isempty(ax)
ax = axes('Units','Normal','Position',[0 0 1 1], ...
'Visible','Off','Tag','TEXTSC');
else
axes(ax)
end
% Place the text
if ischar(y) && ischar(x) && strcmp(lower(y),'title') % Subplot title
txt = x;
x = .5;
tmp = text('Units','normal','String','tmp','Position',[0 0 0]);
ext = get(tmp,'Extent');
delete(tmp)
H = ext(4);
y = 1 - .60*H;
end
h = text(x,y,txt,'VerticalAlignment','Middle', ...
'HorizontalAlignment','Center','interpreter', 'none' );
% Make the original AXES current
if ~isempty(ch)
set(gcf,'CurrentAxes',ch(end));
end
% Check for output
if nargout == 1
H = h;
end