Home > classes > @ao > hist.m

hist

PURPOSE ^

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

SYNOPSIS ^

function varargout = hist(varargin)

DESCRIPTION ^

 HIST overloads the histogram function (hist) of MATLAB for Analysis
 Objects.
 
 Usage: 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
 
 M Hewitson 24-05-07

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

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

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