-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtitle_inside.m
48 lines (46 loc) · 1.44 KB
/
title_inside.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
function t=title_inside(title_text,varargin)
%--------------------------------------------------------------------------
% title_inside.m - Places the title inside the plot so as to conserve
% space.
%
% Usage: title_inside(title_text,fontsize);
%
% Input: title_text * text to display in title
% fontsize (optional) * size of font
% Output: t * text handle
%
% Written by Marshall Crumiller
% email: [email protected]
%--------------------------------------------------------------------------
args=false;
if(exist('varargin','var') && ~isempty(varargin))
args=true;
arglist=[];%varargin{1};
for i = 1:length(varargin)
c=varargin{i};
if(isfloat(c))
if(isvector(c))
temp_s=sprintf('[%g',c(1));
for j=2:length(c)
temp_s=sprintf('%s %g',temp_s,c(j));
end
arglist=sprintf('%s,%s]',arglist,temp_s);
else
arglist=sprintf('%s,[%g]',arglist,c);
end
else
arglist=sprintf('%s,''%s''',arglist,c);
end
end
end
a = axis(gca);
x=(a(1)+a(2))/2;
height=a(4)-a(3);
margin=height*.018;
y=a(4)-margin;
% Generate text
if(args)
eval(sprintf('t=text(x,y,title_text,''horizontalalignment'',''center'',''verticalalignment'',''top''%s);',arglist));
else
t=text(x,y,title_text,'horizontalalignment','center','verticalalignment','top');
end