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

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003