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,'title') 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
0001 % textsc() - places text in screen coordinates and places 0002 % a title at the top of the figure. 0003 % 0004 % Usage: 0005 % H = textsc(X,Y,TXT) places the text string, TXT 0006 % at the normalized coordinates X and Y. H is the 0007 % handle to the text object. 0008 % 0009 % H = textsc(TXT,'title') places a title at the top 0010 % of the figure window. This is useful when you 0011 % want to place a single title above multiple 0012 % subplots. 0013 % 0014 % Notes: textsc creates an invisible AXES which occupies 0015 % the entire FIGURE. The units of the AXES are 0016 % normalized (range from 0 to 1). textsc checks 0017 % all the children of the current FIGURE to determine 0018 % if an AXES exist which meets these criteria already 0019 % exist. If one does, then it places the text relative 0020 % to that AXES. 0021 % 0022 % Author: John L. Galenski, January 21, 1994 0023 0024 % Written by John L. Galenski III 0025 % All Rights Reserved January 21, 1994 0026 % LDM031695jlg 0027 0028 % $Log: textsc.m,v $ 0029 % Revision 1.2 2007/01/26 18:07:16 arno 0030 % *** empty log message *** 0031 % 0032 % Revision 1.1 2002/04/05 17:36:45 jorn 0033 % Initial revision 0034 % 0035 % June 2015, Made compatible with Matlab 2014 0036 0037 function H = textsc(x,y,txt); 0038 0039 % Basic error checking 0040 if nargin < 2 0041 error('TEXTSC requires at least 2 inputs') 0042 end 0043 0044 % Check to see if AXES already exist 0045 ch = get(gcf,'Children'); 0046 ax = findobj(gcf,'Type','axes','Tag','TEXTSC'); 0047 if isempty(ax) 0048 ax = axes('Units','Normal','Position',[0 0 1 1], ... 0049 'Visible','Off','Tag','TEXTSC'); 0050 else 0051 axes(ax) 0052 end 0053 0054 % Place the text 0055 if nargin == 2 & isstr(x) & strcmp(lower(y),'title') % Subplot title 0056 txt = x; 0057 x = .5; 0058 tmp = text('Units','normal','String','tmp','Position',[0 0 0]); 0059 ext = get(tmp,'Extent'); 0060 delete(tmp) 0061 H = ext(4); 0062 y = 1 - .60*H; 0063 end 0064 h = text(x,y,txt,'VerticalAlignment','Middle', ... 0065 'HorizontalAlignment','Center','interpreter', 'none' ); 0066 0067 % Make the original AXES current 0068 if ~isempty(ch) 0069 if verLessThan('matlab', '8.4') 0070 set(gcf,'CurrentAxes',min(ch)) 0071 else 0072 a=1; 0073 axSwitch=0; 0074 while ~axSwitch 0075 try 0076 set(gcf,'CurrentAxes',ch(a)); %needed to be compatible with M2014 0077 axSwitch=1; 0078 % colorbar axes cannot be made current axes 0079 catch 0080 a=a+1; 0081 if a>length(ch), 0082 axSwitch=1; %no axes will work 0083 end 0084 end 0085 end 0086 end 0087 end 0088 0089 % Check for output 0090 if nargout == 1 0091 H = h; 0092 end