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.html,v 1.14 2008/03/31 10:27:33 hewitson Exp $

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

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

 The following call returns a string that contains the routine CVS version:

 >> version = hist(ao,'Version')

 The following call returns a string that contains the routine category:

 >> category = hist(ao,'Category')

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

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003