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)
              plot (history, arg)
              plot (axes_handle, ...)

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

Generated on Tue 22-Jan-2008 10:39:13 by m2html © 2003