Home > FMAToolbox > Plot > SplitTitle.m

SplitTitle

PURPOSE ^

SplitTitle - Split figure title over multiple lines

SYNOPSIS ^

function SplitTitle(h,text,width)

DESCRIPTION ^

SplitTitle - Split figure title over multiple lines

  USAGE

    SplitTitle(text,width)
    SplitTitle(h,text,width)

    h              optional handle (default = gca)
    text           title text
    width          optional line width (in chars, default = 10)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function SplitTitle(h,text,width)
0002 
0003 %SplitTitle - Split figure title over multiple lines
0004 %
0005 %  USAGE
0006 %
0007 %    SplitTitle(text,width)
0008 %    SplitTitle(h,text,width)
0009 %
0010 %    h              optional handle (default = gca)
0011 %    text           title text
0012 %    width          optional line width (in chars, default = 10)
0013 %
0014 
0015 % Copyright (C) 2011 by Michaƫl Zugaro
0016 %
0017 % This program is free software; you can redistribute it and/or modify
0018 % it under the terms of the GNU General Public License as published by
0019 % the Free Software Foundation; either version 3 of the License, or
0020 % (at your option) any later version.
0021 
0022 % Check number of parameters
0023 if nargin < 1,
0024   error('Incorrect number of parameters (type ''help <a href="matlab:help SplitTitle">SplitTitle</a>'' for details).');
0025 end
0026 
0027 % Default values
0028 if nargin == 1,
0029     text = h;
0030     h = gca;
0031     width = 10;
0032 elseif nargin == 2,
0033     if ishandle(h),
0034         width = 10;
0035     else
0036         width = text;
0037         text = h;
0038         h = gca;
0039     end
0040 end
0041 
0042 if ~isiscalar(width),
0043   error('Non-integer width (type ''help <a href="matlab:help SplitTitle">SplitTitle</a>'' for details).');
0044 end
0045 
0046 % Split text across N lines of fixed width
0047 l = length(text);
0048 nLines = ceil(l/width);
0049 start = -width+1;
0050 t = {};
0051 for i = 1:nLines-1,
0052     start = (i-1)*width+1;
0053     t{i} = text(start:start+width-1);
0054 end
0055 t{end+1} = text(start+width:end);
0056 
0057 % Set title
0058 switch lower(get(h,'type')),
0059     case 'uipanel',
0060         set(h,'title',t);
0061     case 'axes',
0062         title(h,t);
0063 end

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005