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.5 2007/10/31 17:03:45 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.5 2007/10/31 17:03:45 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 ALGONAME = mfilename;
0038 VERSION  = '$Id: hist.m,v 1.5 2007/10/31 17:03:45 ingo Exp $';
0039 
0040 %% Check if this is a call for parameters
0041 if nargin == 2
0042   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0043     in = char(varargin{2});
0044     if strcmp(in, 'Params')
0045       varargout{1} = getDefaultPL();
0046       return
0047     elseif strcmp(in, 'Version')
0048       varargout{1} = VERSION;
0049       return
0050     end
0051   end
0052 end
0053 
0054 %---------------- capture input variable names, AOs, and plists
0055 invars = {};
0056 as     = [];
0057 ps     = [];
0058 Nbins  = -1;
0059 Xbins  = [];
0060 for j=1:nargin
0061   if isa(varargin{j}, 'ao')
0062     invars = [invars cellstr(inputname(j))];
0063   end
0064   if isa(varargin{j}, 'ao')
0065     as = [as varargin{j}];
0066   end
0067   if isa(varargin{j}, 'plist')
0068     ps = [ps varargin{j}];
0069   end
0070   if isnumeric(varargin{j})
0071     if length(varargin{j}) > 1
0072       Xbins = varargin{j};
0073     else
0074       Nbins = varargin{j};
0075     end
0076   end
0077 end
0078 
0079 % produce one plist
0080 if isa(ps, 'plist')
0081   pl = combine(ps, getDefaultPL());
0082 else
0083   pl = getDefaultPL();
0084 end
0085 
0086 % If we have X from command input, override plist
0087 if ~isempty(Xbins)
0088   pl = set(pl, 'X', Xbins);
0089 end
0090 
0091 % If we have N from command input, override plist
0092 if Nbins>0
0093   pl = set(pl, 'N', Nbins);
0094 end
0095 
0096 % Get parameters
0097 N = find(pl, 'N');
0098 X = find(pl, 'X');
0099 
0100 %---------------- Loop over input AOs
0101 
0102 % Initialise output
0103 bs = [];
0104 
0105 % start looping
0106 for j=1:numel(as)
0107   a = as(j);
0108 
0109   % get data
0110   [x, y] = get_xy_values(a.data);
0111 
0112   % Histogram this data
0113   if isempty(X)
0114     disp(sprintf('** sorting data into %d bins', N));
0115     [n,x] = hist(y, N);
0116   else
0117     disp(sprintf('** sorting data into %d bins', length(X)));
0118     [n,x] = hist(y, X);
0119   end
0120 
0121   %-------- Build output AOs
0122 
0123   % make a new xydata object
0124   xy = xydata(x, n);
0125   xy = set(xy, 'name', sprintf('hist(%s)', a.data.name));
0126   xy = set(xy, 'xunits', a.data.yunits);
0127   xy = set(xy, 'yunits', 'Count');
0128 
0129   % make a new history object
0130   h = history(ALGONAME, VERSION, pl, a.hist);
0131   h = set(h, 'invars', invars);
0132 
0133   % make output analysis object
0134   b = ao(xy, h);
0135 
0136   % name for this object
0137   if j > length(invars)
0138     n1 = a.name;
0139   else
0140     n1 = invars{j};
0141   end
0142   b  = setnh(b, 'name', sprintf('hist(%s)', n1));
0143   bs = [bs b];
0144 
0145 end % end of AO loop
0146 
0147 % Reshape the ouput to the same size of the input
0148 bs = reshape(bs, size(as));
0149 
0150 
0151 %---------------- Set outputs
0152 varargout{1} = bs;
0153 
0154 %----------------
0155 %----------------
0156 %----------------
0157 %----------------
0158 
0159 %--------------------------------------------------------------------------
0160 
0161 %% Get default params
0162 function plo = getDefaultPL()
0163 
0164 disp('* creating default plist...');
0165 plo = plist();
0166 plo = append(plo, param('N', 10));
0167 plo = append(plo, param('X', []));
0168 disp('* done.');
0169 
0170 
0171 % END

Generated on Fri 02-Nov-2007 19:39:27 by m2html © 2003