Home > classes > @history > plot.m

plot

PURPOSE ^

PLOT plots a history object as a tree diagram.

SYNOPSIS ^

function varargout = plot(hists, varargin)

DESCRIPTION ^

 PLOT plots a history object as a tree diagram.
 
 M Hewitson 02-02-07
 
 $Id: plot.html,v 1.1 2007/06/08 14:15:05 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = plot(hists, varargin)
0002 % PLOT plots a history object as a tree diagram.
0003 %
0004 % M Hewitson 02-02-07
0005 %
0006 % $Id: plot.html,v 1.1 2007/06/08 14:15:05 hewitson Exp $
0007 %
0008 
0009 %
0010 % Note: Some of the code below is taken from Mathworks's treeplot.m
0011 %
0012 
0013 % Output handles for figures and axes
0014 hfig = [];
0015 ax   = [];
0016 at   = [];
0017 
0018 
0019 nhists = length(hists);
0020 for i=1:nhists
0021     
0022   hist = hists(i);
0023   disp(sprintf('--- plotting history %s', hist.name));
0024 
0025   % convert history object to a node list
0026   [n,a, nodes] = getNodes(hist, [], 0, 1, []);
0027   p = [nodes(:).pn];
0028   [x,y,h]=treelayout(p);
0029   f = find(p~=0);
0030   pp = p(f);
0031   X = [x(f); x(pp); repmat(NaN,size(f))];
0032   Y = [y(f); y(pp); repmat(NaN,size(f))];
0033   X = X(:);
0034   Y = Y(:);
0035 
0036   % figure
0037 %   hfig = [hfig figure];
0038   
0039   % axes objects
0040   a = plot (X, Y, 'r--', x, y, 'ro');
0041   if length(a)>1
0042     set(a(2), 'MarkerFaceColor', 'r');
0043     set(a(2), 'MarkerSize', 8);
0044   end
0045   args  = varargin;
0046   while ~isempty(args)
0047     prop = args{1};
0048     val  = args{2};
0049     args = args(3:end);
0050     set(a, prop, val);
0051   end
0052   ax = [ax a];
0053   
0054   % text objects
0055   strs = [];
0056   a    = [];
0057   b    = [];
0058   for j=1:length(x)
0059     % node description
0060     fcnname = getFcnName(nodes(j).names);
0061     str = ['{\bf\color{blue}' num2str(nodes(j).n) ':}{\bf\color{red}' fcnname '}' char(nodes(j).params)];
0062     nlstr = getNodeInputs(nodes(j).invars);
0063     na  = text(x(j), y(j),...
0064                 [wrapstring(strrep(str,'_', '\_'),getappdata(0, 'wrapstringat')) ...
0065                 cellstr(['{\color{magenta} ' strrep(nlstr,'_', '\_') '}'])]);
0066     set(na, 'HorizontalAlignment', 'center');
0067     set(na, 'EdgeColor', 'k', 'Fontsize', 10);
0068     set(na, 'BackgroundColor', 'w');
0069     set(na, 'Margin', 5);
0070     a   = [a na];
0071   end  
0072   at = [at a];
0073     
0074   % xlabel(['height = ' int2str(h)]);
0075   axis([0 1 0 1]);
0076   box off;
0077   axis off;
0078   
0079 end
0080 
0081 % Make outputs
0082 if nargout > 0
0083   varargout{1} = hfig;
0084 end
0085 if nargout > 1
0086   varargout{2} = ax;
0087 end
0088 if nargout > 2
0089   varargout{3} = at;
0090 end
0091 
0092 
0093 %--------------------------------------------------------------------------
0094 % compute strings to display for function name
0095 function fcnname = getFcnName(name)
0096 
0097 switch name
0098   case 'mtimes'
0099     fcnname = '\times';
0100   case 'times'
0101     fcnname = '\times';
0102   case 'plus'
0103     fcnname = '+';    
0104   case 'minus'
0105     fcnname = '-';    
0106   case 'sqrt'
0107     fcnname = '\surd';    
0108   case 'mrdivide'
0109     fcnname = '/';    
0110   case 'rdivide'
0111     fcnname = '/';    
0112   otherwise
0113     fcnname = char(name);
0114 end
0115 
0116 
0117 %--------------------------------------------------------------------------
0118 % compute strings to display for inputs to nodes
0119 function    str = getNodeInputs(invars);
0120 
0121 ni = length(invars);
0122 if ni > 0
0123   str = char(invars{1});
0124   for iv=2:ni
0125     s = char(invars{iv});
0126     if ~strcmp(s, 'pl')
0127       str = [str '  ' s];
0128     end
0129   end
0130 else
0131   str = '';
0132 end
0133 
0134

Generated on Fri 08-Jun-2007 16:09:11 by m2html © 2003