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.23 2008/09/05 11:05:29 ingo 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.23 2008/09/05 11:05:29 ingo 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     % Keep the data shape of the input AO
0077     if size(bs(j).data.y, 1) ~= 1
0078       x = x.';
0079       n = n.';
0080     end
0081     % make a new xydata object
0082     xy = xydata(x, n);
0083     xy.setXunits(bs(j).data.yunits);
0084     xy.setYunits('Count');
0085     % make output analysis object
0086     bs(j).data = xy;
0087     % name for this object
0088     bs(j).setName(sprintf('hist(%s)', ao_invars{j}), 'internal');
0089     % Add history
0090     bs(j).addHistory(getInfo, pl, ao_invars(j), bs(j).hist);
0091     % Add to outputs
0092   end % end of AO loop
0093 
0094   % Set outputs
0095   varargout{1} = bs;
0096 end
0097 
0098 %--------------------------------------------------------------------------
0099 % Get Info Object
0100 %--------------------------------------------------------------------------
0101 function ii = getInfo(varargin)
0102   if nargin == 1 && strcmpi(varargin{1}, 'None')
0103     sets = {};
0104     pls   = [];
0105   elseif nargin == 1 && ~isempty(varargin{1}) && ischar(varargin{1})
0106     sets{1} = varargin{1};
0107     pls = getDefaultPlist(sets{1});
0108   else
0109     sets = {'Number of bins', 'Bin centres'};
0110     pls = [];
0111     for kk=1:numel(sets)
0112       pls = [pls getDefaultPlist(sets{kk})];
0113     end
0114   end
0115   % Build info object
0116   ii = minfo(mfilename, 'ao', '', utils.const.categories.sigproc, '$Id: hist.m,v 1.23 2008/09/05 11:05:29 ingo Exp $', sets, pls);
0117 end
0118 
0119 %--------------------------------------------------------------------------
0120 % Get Default Plist
0121 %--------------------------------------------------------------------------
0122 
0123 function plo = getDefaultPlist(set)
0124   switch set
0125     case 'Number of bins'
0126       plo = plist('N', 10);
0127     case 'Bin centres'
0128       plo = plist('X', []);
0129     otherwise
0130       error('### Unknown default plist for the set [%s]', set);
0131   end
0132 end
0133 
0134

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003