Home > classes > @history > plot.m

plot

PURPOSE ^

PLOT plots a history object as a tree diagram.

SYNOPSIS ^

function varargout = plot(varargin)

DESCRIPTION ^

 PLOT plots a history object as a tree diagram.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: PLOT plots a history object as a tree diagram.

 CALL: plot (                  history, arg)
       plot (curr_axes_handle, history, arg)

 VERSION: $Id: plot.m,v 1.13 2007/07/11 16:01:24 ingo Exp $

 NOTE:    Some of the code below is taken from Mathworks's treeplot.m

 HISTORY: 02-02-07 M Hewitson
             Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = plot(varargin)
0002 % PLOT plots a history object as a tree diagram.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: PLOT plots a history object as a tree diagram.
0007 %
0008 % CALL: plot (                  history, arg)
0009 %       plot (curr_axes_handle, history, arg)
0010 %
0011 % VERSION: $Id: plot.m,v 1.13 2007/07/11 16:01:24 ingo Exp $
0012 %
0013 % NOTE:    Some of the code below is taken from Mathworks's treeplot.m
0014 %
0015 % HISTORY: 02-02-07 M Hewitson
0016 %             Creation
0017 %
0018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0019 
0020 %% Used call: plot (history, arg)
0021 if isa(varargin{1}, 'history')
0022 
0023   hists = varargin{1};
0024   curr_axes = axes;
0025   if nargin >= 2
0026     varargin = varargin(2:end);
0027   else
0028     varargin = {};
0029   end
0030 
0031 %% Used call: plot (curr_axes_handle, history, arg)
0032 elseif ishandle(varargin{1})
0033 
0034   curr_axes = varargin{1};
0035   axes(curr_axes);
0036   hists = varargin{2};
0037   if nargin >= 3
0038     varargin = varargin(3:end);
0039   else
0040     varargin = {};
0041   end
0042 
0043 else
0044   error (['### the first input should be a history object or an axes handle' ...
0045          sprintf(' varargin{1} = [%s]',varargin{1})]);
0046 end
0047 
0048 %% collect the parameter andput them into the parameter list
0049 plot_args = {};
0050 pl        = plist();
0051 args      = varargin;
0052 
0053 while ~isempty(args)
0054   arg = args{1};
0055 
0056   if isa(arg, 'plist')
0057     pl = append(pl, arg);
0058     args = args(2:end);
0059 
0060   % Add the key-values to the parameter list
0061   elseif ischar(arg)
0062     if  length(args) > 1
0063       val = args{2};
0064       pl = append(pl, param(arg, val));
0065     else
0066       error('### the key [%s] have no value',arg);
0067     end
0068     args = args(3:end);
0069     plot_args{end+1} = arg;
0070     plot_args{end+1} = val;
0071   end
0072 
0073 end
0074 
0075 
0076 %% Comes the call from the browser or from the command window
0077 max_depth = find(pl, 'max_depth');
0078 
0079 %% Output handles for figures and axes
0080 
0081 hfig = [];
0082 ax   = [];
0083 at   = [];
0084 
0085 nhists = length(hists);
0086 for i=1:nhists
0087 
0088   hist = hists(i);
0089   disp(sprintf('--- plotting history %s', hist.name));
0090 
0091   % convert history object to a node list
0092   if ~isempty(max_depth)
0093     [n,a, nodes] = getNodes_plot(hist, [], 0, 1, [], 0, max_depth);
0094   else
0095     [n,a, nodes] = getNodes(hist, [], 0, 1, []);
0096   end
0097   p = [nodes(:).pn];
0098   [x,y,h]=treelayout(p);
0099   f = find(p~=0);
0100   pp = p(f);
0101   X = [x(f); x(pp); repmat(NaN,size(f))];
0102   Y = [y(f); y(pp); repmat(NaN,size(f))];
0103   X = X(:);
0104   Y = Y(:);
0105 
0106   % figure
0107 %   hfig = [hfig figure];
0108 
0109   % axes objects
0110   a = plot (curr_axes, X, Y, 'r--', x, y, 'ro');
0111   % plot (X,Y) --> die linien
0112   if length(a)>1
0113     set(a(2), 'MarkerFaceColor', 'r');
0114     set(a(2), 'MarkerSize', 8);
0115   end
0116   args  = plot_args;
0117   while ~isempty(args)
0118     prop = args{1};
0119     val  = args{2};
0120     args = args(3:end);
0121     set(a, prop, val);
0122   end
0123   ax = [ax a];
0124 
0125   % text objects
0126   a    = [];
0127   for j=1:length(x)
0128     % node description
0129     fcnname = getFcnName(nodes(j).names);
0130     str = ['{\bf\color{blue}' num2str(nodes(j).n) ':}{\bf\color{red}' fcnname '}' char(nodes(j).params)];
0131     nlstr = getNodeInputs(nodes(j).invars);
0132 
0133     na  = text(x(j), y(j),...
0134                 [wrapstring(strrep(str,'_', '\_'),getappdata(0, 'wrapstringat')) ...
0135                 cellstr(['{\color{magenta} ' strrep(nlstr,'_', '\_') '}'])]);
0136     set(na, 'HorizontalAlignment', 'center');
0137     set(na, 'EdgeColor', 'k', 'Fontsize', 10);
0138     set(na, 'BackgroundColor', 'w');
0139     set(na, 'Margin', 5);
0140     a   = [a na];
0141   end
0142   at = [at a];
0143 
0144   % xlabel(['height = ' int2str(h)]);
0145   axis([0 1 0 1]);
0146   box off;
0147   axis off;
0148 
0149 end
0150 
0151 % Make outputs
0152 if nargout > 0
0153   varargout{1} = hfig;
0154 end
0155 if nargout > 1
0156   varargout{2} = ax;
0157 end
0158 if nargout > 2
0159   varargout{3} = at;
0160 end
0161 
0162 
0163 %--------------------------------------------------------------------------
0164 % compute strings to display for function name
0165 function fcnname = getFcnName(name)
0166 
0167 switch name
0168   case 'mtimes'
0169     fcnname = '\times';
0170   case 'times'
0171     fcnname = '\times';
0172   case 'plus'
0173     fcnname = '+';
0174   case 'minus'
0175     fcnname = '-';
0176   case 'sqrt'
0177     fcnname = '\surd';
0178   case 'mrdivide'
0179     fcnname = '/';
0180   case 'rdivide'
0181     fcnname = '/';
0182   otherwise
0183     fcnname = char(name);
0184 end
0185 
0186 
0187 %--------------------------------------------------------------------------
0188 % compute strings to display for inputs to nodes
0189 function    str = getNodeInputs(invars)
0190 
0191 ni = length(invars);
0192 if ni > 0
0193   str = char(invars{1});
0194   for iv=2:ni
0195     s = char(invars{iv});
0196     if ~strcmp(s, 'pl')
0197       str = [str '  ' s];
0198     end
0199   end
0200 else
0201   str = '';
0202 end
0203 
0204

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003