Home > chronux_1_50 > spikesort > histxt.m

histxt

PURPOSE ^

HISTXT Column-by-column Histograms.

SYNOPSIS ^

function [counts,t_inds,x_inds] = histxt(x, varargin)

DESCRIPTION ^

HISTXT            Column-by-column Histograms.
   COUNTS = HISTXT(X,D), where X is an M x T matrix returns a D x T
   matrix COUNTS in which each column contains the histogrammed (with D
   bins) values from the corresponding column in X.  If D is not
   specified (or is the empty matrix), it defaults to 100.

   [COUNTS,T_INDS,X_INDS] = HISTXT(X,D) returns the column indices and
   bin centers so that the density can be visualized with
   IMAGESC(T_INDS,X_INDS,COUNTS).

   [...] = HISTXT(...,'log') uses the log of the counts (0's yield -Inf).

   HISTXT(...) without output arguments produces an image of the counts.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [counts,t_inds,x_inds] = histxt(x, varargin)
0002 %HISTXT            Column-by-column Histograms.
0003 %   COUNTS = HISTXT(X,D), where X is an M x T matrix returns a D x T
0004 %   matrix COUNTS in which each column contains the histogrammed (with D
0005 %   bins) values from the corresponding column in X.  If D is not
0006 %   specified (or is the empty matrix), it defaults to 100.
0007 %
0008 %   [COUNTS,T_INDS,X_INDS] = HISTXT(X,D) returns the column indices and
0009 %   bin centers so that the density can be visualized with
0010 %   IMAGESC(T_INDS,X_INDS,COUNTS).
0011 %
0012 %   [...] = HISTXT(...,'log') uses the log of the counts (0's yield -Inf).
0013 %
0014 %   HISTXT(...) without output arguments produces an image of the counts.
0015 
0016 %%%%%%%%%%%%%%%%%%%%%%%%%%%% Parse Inputs %%%%%%%%%%%%%%%%%%%%%%%%%%%%
0017 D = 100;  logflag = 0;                        % defaults
0018 
0019 [M,T] = size(x);
0020 if (~isnumeric(x) || ndims(x)~=2 || any(isinf(x(:))))
0021     error('First input argument must be a 2-D numeric matrix with no +/- Inf elements.');
0022 end
0023 mask = isnan(x);   nanflag = any(mask(:));
0024 if (nanflag),  warning('NaN elements will be ignored.');  end
0025 
0026 if (length(varargin) > 0)
0027     tail = varargin{end};
0028     if (ischar(tail) && strcmpi(tail,'log'))  % If the last arg was 'log' ...
0029         varargin = varargin(1:(end-1));       % ... chomp it and set a flag.
0030         logflag = 1;
0031     end
0032     if (length(varargin) > 0)
0033         tail = varargin{end};
0034         if (isnumeric(tail) && length(tail)==1)   % If next to last arg was a scalar, ...
0035             varargin = varargin(1:end-1);         % ... chomp it and set the bin count.
0036             D = tail;
0037         end
0038     end
0039     if (length(varargin) > 0),  error('Unknown syntax.');  end;
0040 end
0041 
0042 
0043 %%%%%%%%%%%%%%%%%%%%%%%%%%%% Rescale Data %%%%%%%%%%%%%%%%%%%%%%%%%%%%
0044 % Scale the data
0045 [x,oldmin,oldmax] = rescale(x,1,D);  x = round(x);
0046 
0047 % Make bin centers/column indices
0048 x_inds = linspace(oldmin,oldmax,D);
0049 t_inds = 1:T;
0050 
0051 % Mask NaNs
0052 if (nanflag),  D = D+1;  x(mask) = D;  end
0053 
0054 
0055 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Histogram %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0056 counts = CORE_histxt(x,D);
0057 
0058 
0059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Clean Up %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0060 if (nanflag), counts(end,:) = [];  D = D-1;  end;
0061 if (logflag), o=warning('off');  counts=log(counts);  warning(o);  end;
0062     
0063 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Graphics %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0064 if (nargout == 0)
0065      imagesc(t_inds, x_inds, counts);   axis xy;
0066      clear counts t_inds x_inds  % clear these so nothing is dumped to output
0067 end

Generated on Mon 09-Oct-2006 00:54:52 by m2html © 2003