Home > classes > @ao > hist.m

hist

PURPOSE ^

HIST overloads the histogram function (hist) of MATLAB for Analysis Objects.

SYNOPSIS ^

function varargout = hist(varargin)

DESCRIPTION ^

 HIST overloads the histogram function (hist) of MATLAB for Analysis Objects.

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

 DESCRIPTION: HIST overloads the histogram function (hist) of MATLAB for
              Analysis Objects.

 CALL:        b = hist(a)
              b = hist(a, N)
              b = hist(a, X)
              b = hist(a, pl)

 INPUTS:      a  - input analysis object(s)
              N  - number of bins
              X  - specify centers of bins
              pl - a parameter list

 OUTPUTS:     b  - xydata type analysis object(s) containing the
                   histogrammed data

 PARAMETERS:  'N'    - number of bins
              'X'    - set of bin centers

 VERSION:     $Id: hist.m,v 1.3 2007/06/22 08:32:49 ingo Exp $

 The following call returns a parameter list object that contains the
 default parameter values:

 >> pl = hist(ao, 'Params')

 HISTORY: 24-05-07 M Hewitson
             Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = hist(varargin)
0002 % HIST overloads the histogram function (hist) of MATLAB for Analysis Objects.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: HIST overloads the histogram function (hist) of MATLAB for
0007 %              Analysis Objects.
0008 %
0009 % CALL:        b = hist(a)
0010 %              b = hist(a, N)
0011 %              b = hist(a, X)
0012 %              b = hist(a, pl)
0013 %
0014 % INPUTS:      a  - input analysis object(s)
0015 %              N  - number of bins
0016 %              X  - specify centers of bins
0017 %              pl - a parameter list
0018 %
0019 % OUTPUTS:     b  - xydata type analysis object(s) containing the
0020 %                   histogrammed data
0021 %
0022 % PARAMETERS:  'N'    - number of bins
0023 %              'X'    - set of bin centers
0024 %
0025 % VERSION:     $Id: hist.m,v 1.3 2007/06/22 08:32:49 ingo Exp $
0026 %
0027 % The following call returns a parameter list object that contains the
0028 % default parameter values:
0029 %
0030 % >> pl = hist(ao, 'Params')
0031 %
0032 % HISTORY: 24-05-07 M Hewitson
0033 %             Creation
0034 %
0035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0036 
0037 %% Check if this is a call for parameters
0038 if nargin == 2
0039   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0040     in = char(varargin{2});
0041     if strcmp(in, 'Params')
0042       varargout{1} = getDefaultPL();
0043       return
0044     end
0045   end
0046 end
0047 
0048 %---------------- Standard history variable
0049 
0050 ALGONAME = mfilename;
0051 VERSION  = '$Id: hist.m,v 1.3 2007/06/22 08:32:49 ingo Exp $';
0052 
0053 %---------------- capture input variable names, AOs, and plists
0054 invars = {};
0055 as     = [];
0056 ps     = [];
0057 Nbins  = -1;
0058 Xbins  = [];
0059 for j=1:nargin
0060   if isa(varargin{j}, 'ao')
0061     invars = [invars cellstr(inputname(j))];
0062   end
0063   if isa(varargin{j}, 'ao')
0064     as = [as varargin{j}];
0065   end
0066   if isa(varargin{j}, 'plist')
0067     ps = [ps varargin{j}];
0068   end
0069   if isnumeric(varargin{j})
0070     if length(varargin{j}) > 1
0071       Xbins = varargin{j};
0072     else
0073       Nbins = varargin{j};
0074     end
0075   end
0076 end
0077 
0078 % produce one plist
0079 if isa(ps, 'plist')
0080   pl = combine(ps, getDefaultPL());
0081 else
0082   pl = getDefaultPL();
0083 end
0084 
0085 % If we have X from command input, override plist
0086 if ~isempty(Xbins)
0087   pl = set(pl, 'X', Xbins);
0088 end
0089 
0090 % If we have N from command input, override plist
0091 if Nbins>0
0092   pl = set(pl, 'N', Nbins);
0093 end
0094 
0095 % number of input AOs
0096 na = length(as);
0097 
0098 
0099 % Get parameters
0100 N = find(pl, 'N');
0101 X = find(pl, 'X');
0102 
0103 %---------------- Loop over input AOs
0104 
0105 % Initialise output
0106 bs = [];
0107 
0108 % start looping
0109 for j=1:na
0110   a = as(j);
0111 
0112   % get data
0113   y = getAOdata(a);
0114 
0115   % Histogram this data
0116   if isempty(X)
0117     disp(sprintf('** sorting data into %d bins', N));
0118     [n,x] = hist(y, N);
0119   else
0120     disp(sprintf('** sorting data into %d bins', length(X)));
0121     [n,x] = hist(y, X);
0122   end
0123 
0124   %-------- Build output AOs
0125 
0126   % make a new xydata object
0127   xy = xydata(x, n);
0128   xy = set(xy, 'name', sprintf('hist(%s)', a.data.name));
0129   xy = set(xy, 'xunits', a.data.yunits);
0130   xy = set(xy, 'yunits', 'Count');
0131 
0132   % make a new history object
0133   h = history(ALGONAME, VERSION, pl, a.hist);
0134   h = set(h, 'invars', invars);
0135 
0136   % make output analysis object
0137   b = ao(xy, h);
0138 
0139   % name for this object
0140   if isempty(invars{j})
0141     n1 = a.name;
0142   else
0143     n1 = invars{j};
0144   end
0145   b  = set(b, 'name', sprintf('hist(%s)', n1));
0146   bs = [bs b];
0147 
0148 end % end of AO loop
0149 
0150 %---------------- Set outputs
0151 varargout{1} = bs;
0152 
0153 %----------------
0154 %----------------
0155 %----------------
0156 %----------------
0157 
0158 %--------------------------------------------------------------------------
0159 
0160 %% Get default params
0161 function plo = getDefaultPL()
0162 
0163 disp('* creating default plist...');
0164 plo = plist();
0165 plo = append(plo, param('N', 10));
0166 plo = append(plo, param('X', []));
0167 disp('* done.');
0168 
0169 
0170 % END

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