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

Generated on Tue 26-Feb-2008 10:52:52 by m2html © 2003