comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % LEGENDADD Add a string to the current legend.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: LEGENDADD Add a string to the current legend.
5 %
6 % CALL: legendAdd(fig, 'string')
7 % plot (curr_axes_handle, history, arg)
8 %
9 % INPUT: fig = figure handle (gcf, for example)
10 % string = string to add
11 %
12 % VERSION: $Id: legendAdd.m,v 1.1 2008/08/05 17:51:32 ingo Exp $
13 %
14 % HISTORY: 26-01-07 M Hewitson
15 % Creation
16 %
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18
19 function legendAdd(varargin)
20
21 if nargin ~=2
22 error('usage: legendAdd(fig, ''strin'')');
23 end
24
25 fig = varargin{1};
26 strin = varargin{2};
27
28 if ~ischar(strin)
29 error('arg 2 is not a string > usage: legendAdd(fig, ''strin'')');
30 end
31 % if ~isobject(fig)
32 % error('arg 1 is not an object > usage: legendAdd(fig, ''strin'')');
33 % end
34
35 % get the current legend strings
36
37
38 ch = get(gcf, 'Children');
39 leg = [];
40
41 for j=1:length(ch)
42
43 tag = get(ch(j), 'Tag');
44
45 if strcmp(tag, 'legend')
46 leg = get(ch(j));
47 end
48
49 end
50 str = [];
51 % get(leg, 'XLabel')
52 if ~isempty(leg)
53 for j=length(leg.Children):-1:1
54
55 ch = leg.Children(j);
56
57 tag = get(ch, 'Tag');
58
59 if ~strcmp(tag, '')
60
61 str = strvcat(str, tag);
62 end
63 end
64 end
65
66 str = strvcat(str, strin);
67
68 legend(str);
69
70 end
71