LTPDA_LEGENDADD Add a string to the current legend. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: LTPDA_LEGENDADD Add a string to the current legend. CALL: legendAdd(fig, 'string') plot (curr_axes_handle, history, arg) INPUT: fig = figure handle (gcf, for example) string = string to add VERSION: $Id: ltpda_legendAdd.m,v 1.4 2007/06/07 08:56:24 ingo Exp $ HISTORY: 26-01-07 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function ltpda_legendAdd(varargin) 0002 % LTPDA_LEGENDADD Add a string to the current legend. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: LTPDA_LEGENDADD Add a string to the current legend. 0007 % 0008 % CALL: legendAdd(fig, 'string') 0009 % plot (curr_axes_handle, history, arg) 0010 % 0011 % INPUT: fig = figure handle (gcf, for example) 0012 % string = string to add 0013 % 0014 % VERSION: $Id: ltpda_legendAdd.m,v 1.4 2007/06/07 08:56:24 ingo Exp $ 0015 % 0016 % HISTORY: 26-01-07 M Hewitson 0017 % Creation 0018 % 0019 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0020 0021 0022 if nargin ~=2 0023 error('usage: legendAdd(fig, ''strin'')'); 0024 end 0025 0026 fig = varargin{1}; 0027 strin = varargin{2}; 0028 0029 if ~ischar(strin) 0030 error('arg 2 is not a string > usage: legendAdd(fig, ''strin'')'); 0031 end 0032 % if ~isobject(fig) 0033 % error('arg 1 is not an object > usage: legendAdd(fig, ''strin'')'); 0034 % end 0035 0036 % get the current legend strings 0037 0038 0039 ch = get(gcf, 'Children'); 0040 leg = []; 0041 0042 for j=1:length(ch) 0043 0044 tag = get(ch(j), 'Tag'); 0045 0046 if strcmp(tag, 'legend') 0047 leg = get(ch(j)); 0048 end 0049 0050 end 0051 str = []; 0052 % get(leg, 'XLabel') 0053 if ~isempty(leg) 0054 for j=length(leg.Children):-1:1 0055 0056 ch = leg.Children(j); 0057 0058 tag = get(ch, 'Tag'); 0059 0060 if ~strcmp(tag, '') 0061 0062 str = strvcat(str, tag); 0063 end 0064 end 0065 end 0066 0067 str = strvcat(str, strin); 0068 0069 legend(str); 0070