diff m-toolbox/classes/+utils/@plottools/legendAdd.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/classes/+utils/@plottools/legendAdd.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,71 @@
+% LEGENDADD Add a string to the current legend.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% DESCRIPTION: 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: legendAdd.m,v 1.1 2008/08/05 17:51:32 ingo Exp $
+%
+% HISTORY: 26-01-07 M Hewitson
+%             Creation
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function legendAdd(varargin)
+
+  if nargin ~=2
+    error('usage: legendAdd(fig, ''strin'')');
+  end
+
+  fig = varargin{1};
+  strin = varargin{2};
+
+  if ~ischar(strin)
+    error('arg 2 is not a string > usage: legendAdd(fig, ''strin'')');
+  end
+  % if ~isobject(fig)
+  %   error('arg 1 is not an object > usage: legendAdd(fig, ''strin'')');
+  % end
+
+  % get the current legend strings
+
+
+  ch = get(gcf, 'Children');
+  leg = [];
+
+  for j=1:length(ch)
+
+    tag = get(ch(j), 'Tag');
+
+    if strcmp(tag, 'legend')
+      leg = get(ch(j));
+    end
+
+  end
+  str = [];
+  % get(leg, 'XLabel')
+  if ~isempty(leg)
+    for j=length(leg.Children):-1:1
+
+      ch = leg.Children(j);
+
+      tag = get(ch, 'Tag');
+
+      if ~strcmp(tag, '')
+
+        str = strvcat(str, tag);
+      end
+    end
+  end
+
+  str = strvcat(str, strin);
+
+  legend(str);
+
+end
+