Home > matutils > hfill.m

hfill

PURPOSE ^

[bincenter,n] = hfill(vals,nbin,low,high,weight,opt)

SYNOPSIS ^

function [bincenter,n] = hfill(vals,nbin,low,high,weights,opt)

DESCRIPTION ^

 [bincenter,n] = hfill(vals,nbin,low,high,weight,opt)

 Histogram data into equally sized bins specified by number
 and range.

 vals are the events to be binned
 nbin defaults to 10
 low edge of the bins defaults to min(vals)
 high edge of the bins defaults to max(vals)
 weight of the events default to 1
 opt to be passed through to hplot when plotting
 
 If no output specified plots the resulting histogram.

 eg: hfill(randn(100),100,-3,3,rand(100));

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [bincenter,n] = hfill(vals,nbin,low,high,weights,opt)
0002 % [bincenter,n] = hfill(vals,nbin,low,high,weight,opt)
0003 %
0004 % Histogram data into equally sized bins specified by number
0005 % and range.
0006 %
0007 % vals are the events to be binned
0008 % nbin defaults to 10
0009 % low edge of the bins defaults to min(vals)
0010 % high edge of the bins defaults to max(vals)
0011 % weight of the events default to 1
0012 % opt to be passed through to hplot when plotting
0013 %
0014 % If no output specified plots the resulting histogram.
0015 %
0016 % eg: hfill(randn(100),100,-3,3,rand(100));
0017 
0018 if(isempty(vals))
0019   error('Must provide data to histogram');
0020 end
0021 
0022 if(~exist('nbin'))
0023   nbin=[];
0024 end
0025 if(~exist('low'))
0026   low=[];
0027 end
0028 if(~exist('high'))
0029   high=[];
0030 end
0031 if(~exist('weights'))
0032   weights=[];
0033 end
0034 if(~exist('opt'))
0035   opt=' ';
0036 end
0037 
0038 % Set weights if not provided
0039 if(isempty(weights))
0040   weights=ones(size(vals));
0041 end
0042 
0043 if((~isreal(vals))|(~isreal(weights)))
0044   error('Data (and weights) must be real');
0045 end
0046 
0047 % Max and min require vector data
0048 vals=vals(:)'; weights=weights(:)';
0049 
0050 if(isempty(nbin))
0051   nbin=10;
0052 end
0053 if(isempty(low))
0054   low=min(vals);
0055 end
0056 if(isempty(high))
0057   high=max(vals);
0058   % Make max just fall in top bin
0059   high=high+(high-low)*1e-9;
0060 end
0061 
0062 % If there is non-finite data remove it
0063 if(sum(~isfinite(vals))>0)
0064   ind=isfinite(vals);
0065   vals=vals(ind);
0066   weights=weights(ind);
0067   warning('Non-finite input data (removed)');
0068 end
0069 
0070 [bincenter,n]=hfill(vals,nbin,low,high,weights);
0071 % C code for speed
0072 %[bincenter,n]=hfillc(vals,nbin,low,high,weights);
0073 
0074 if(nargout==0)
0075   hplot(bincenter,n,opt);
0076 end

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005