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, pl)

 INPUTS:      a  - input analysis object(s)
              pl - a parameter list

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

 PARAMETERS:  'N'    - number of bins [default: 10]
              'X'    - set of bin centers

 WARNING: the '.' method of calling hist() doesn't work since AOs have a
 property called 'hist'. Use the standard function call instead:

    >> a.hist  % returns the history object and doesn't call ao/hist
    >> hist(a) % calls ao/hist

 M-FILE INFO: Get information about this methods by calling
              >> ao.getInfo('hist')

              Get information about a specified set-plist by calling:
              >> ao.getInfo('hist', 'Number of bins')

 VERSION:     $Id: hist.m,v 1.21 2008/08/08 12:28:47 hewitson Exp $

 HISTORY:     24-05-07 M Hewitson
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % HIST overloads the histogram function (hist) of MATLAB for Analysis Objects.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: HIST overloads the histogram function (hist) of MATLAB for
0005 %              Analysis Objects.
0006 %
0007 % CALL:        b = hist(a)
0008 %              b = hist(a, pl)
0009 %
0010 % INPUTS:      a  - input analysis object(s)
0011 %              pl - a parameter list
0012 %
0013 % OUTPUTS:     b  - xydata type analysis object(s) containing the
0014 %                   histogrammed data
0015 %
0016 % PARAMETERS:  'N'    - number of bins [default: 10]
0017 %              'X'    - set of bin centers
0018 %
0019 % WARNING: the '.' method of calling hist() doesn't work since AOs have a
0020 % property called 'hist'. Use the standard function call instead:
0021 %
0022 %    >> a.hist  % returns the history object and doesn't call ao/hist
0023 %    >> hist(a) % calls ao/hist
0024 %
0025 % M-FILE INFO: Get information about this methods by calling
0026 %              >> ao.getInfo('hist')
0027 %
0028 %              Get information about a specified set-plist by calling:
0029 %              >> ao.getInfo('hist', 'Number of bins')
0030 %
0031 % VERSION:     $Id: hist.m,v 1.21 2008/08/08 12:28:47 hewitson Exp $
0032 %
0033 % HISTORY:     24-05-07 M Hewitson
0034 %                 Creation
0035 %
0036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0037 
0038 function varargout = hist(varargin)
0039 
0040   % Check if this is a call for parameters
0041   if utils.helper.isinfocall(varargin{:})
0042     varargout{1} = getInfo(varargin{3});
0043     return
0044   end
0045 
0046   import utils.const.*
0047   utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0048   
0049   % Collect input variable names
0050   in_names = cell(size(varargin));
0051   for ii = 1:nargin,in_names{ii} = inputname(ii);end
0052 
0053   % Collect all AOs and plists
0054   [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
0055   [pli, pl_invars, rest] = utils.helper.collect_objects(varargin(:), 'plist', in_names);
0056 
0057   pl = combine(pli, getDefaultPlist('Number of bins'));
0058   
0059   % Decide on a deep copy or a modify
0060   bs = copy(as, nargout);
0061 
0062   % Get parameters
0063   N = find(pl, 'N');
0064   X = find(pl, 'X');
0065 
0066   %---------------- Loop over input AOs
0067 
0068   % start looping
0069   for j=1:numel(bs)
0070     % Histogram this data
0071     if isempty(X)
0072       [n,x] = hist(bs(j).data.y, N);
0073     else
0074       [n,x] = hist(bs(j).data.y, X);
0075     end
0076     % make a new xydata object
0077     xy = xydata(x, n);
0078     xy.setXunits(bs(j).data.yunits);
0079     xy.setYunits('Count');
0080     % make output analysis object
0081     bs(j).data = xy;
0082     % name for this object
0083     bs(j).setName(sprintf('hist(%s)', ao_invars{j}), 'internal');
0084     % Add history
0085     bs(j).addHistory(getInfo, pl, ao_invars(j), bs(j).hist);
0086     % Add to outputs
0087   end % end of AO loop
0088 
0089   % Set outputs
0090   varargout{1} = bs;
0091 end
0092 
0093 %--------------------------------------------------------------------------
0094 % Get Info Object
0095 %--------------------------------------------------------------------------
0096 function ii = getInfo(varargin)
0097   if nargin == 1 && strcmpi(varargin{1}, 'None')
0098     sets = {};
0099     pls   = [];
0100   elseif nargin == 1 && ~isempty(varargin{1}) && ischar(varargin{1})
0101     sets{1} = varargin{1};
0102     pls = getDefaultPlist(sets{1});
0103   else
0104     sets = {'Number of bins', 'Bin centres'};
0105     pls = [];
0106     for kk=1:numel(sets)
0107       pls = [pls getDefaultPlist(sets{kk})];
0108     end
0109   end
0110   % Build info object
0111   ii = minfo(mfilename, 'ao', '', 'Signal Processing', '$Id: hist.m,v 1.21 2008/08/08 12:28:47 hewitson Exp $', sets, pls);
0112 end
0113 
0114 %--------------------------------------------------------------------------
0115 % Get Default Plist
0116 %--------------------------------------------------------------------------
0117 
0118 function plo = getDefaultPlist(set)
0119   switch set
0120     case 'Number of bins'
0121       plo = plist('N', 10);
0122     case 'Bin centres'
0123       plo = plist('X', []);
0124     otherwise
0125       error('### Unknown default plist for the set [%s]', set);
0126   end
0127 end
0128 
0129

Generated on Mon 25-Aug-2008 22:39:29 by m2html © 2003