Home > chronux_1_50 > spikesort > CORE_minmax.m

CORE_minmax   Windows

PURPOSE ^

CORE_MINMAX Core computational routine for MINMAX.

SYNOPSIS ^

function [xmn,xmx,mni,mxi] = CORE_minmax_(x)

DESCRIPTION ^

CORE_MINMAX       Core computational routine for MINMAX.
   [XMN,XMX,MNI,MXI] = CORE_MINMAX(X) returns scalars such that
   XMN = X(MNI) = min(X) and XMX = X(MXI) = max(X).  Ties in indices are
   broken in favor of the lowest magnitude index.
   
   NaN values are ignored unless the input is all NaN.  In this case, XMN
   and XMX are set to NaN, while MNI and MXI are set to 1.  This mimics
   the behavior of the Matlab native MIN/MAX functions. 

   CONDITIONS
   ----------
   X must be a real vector of type DOUBLE.  An N-D array X is treated as X(:).
   Infinite values are allowed.   NaN's are ignored (see above).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [xmn,xmx,mni,mxi] = CORE_minmax_(x)
0002 %CORE_MINMAX       Core computational routine for MINMAX.
0003 %   [XMN,XMX,MNI,MXI] = CORE_MINMAX(X) returns scalars such that
0004 %   XMN = X(MNI) = min(X) and XMX = X(MXI) = max(X).  Ties in indices are
0005 %   broken in favor of the lowest magnitude index.
0006 %
0007 %   NaN values are ignored unless the input is all NaN.  In this case, XMN
0008 %   and XMX are set to NaN, while MNI and MXI are set to 1.  This mimics
0009 %   the behavior of the Matlab native MIN/MAX functions.
0010 %
0011 %   CONDITIONS
0012 %   ----------
0013 %   X must be a real vector of type DOUBLE.  An N-D array X is treated as X(:).
0014 %   Infinite values are allowed.   NaN's are ignored (see above).
0015 
0016 [xmn,mni] = min(x(:));
0017 [xmx,mxi] = max(x(:));
0018 
0019 return;
0020 
0021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% TEST CODE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0024 % N = 5e6;
0025 % array = randn(N,1);  array(1:1e4:end) = NaN;
0026 % % array = [1:N];     array(1:10:end) = NaN;  % much slower
0027 % tic; [mminval,mmaxval,mminind,mmaxind] = CORE_minmax(array);  t(1) = toc;
0028 % tic; [minval,minind] = min(array);   [maxval,maxind] = max(array); t(2) = toc;
0029 % printf('CORE_minmax took %5.3f sec and Matlab code took %5.3f sec.', t(1), t(2));
0030 % if (~isequal([mminval,mmaxval,mminind,mmaxind], [minval,maxval,minind,maxind]))
0031 %     printf('The two calls did not produce the same results.');
0032 % end
0033

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