



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. 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.


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 % CONDITIONS 0008 % ---------- 0009 % X must be a real vector of type DOUBLE. An N-D array X is treated as X(:). 0010 % Infinite values are allowed. NaN's are ignored. 0011 0012 [xmn,mni] = min(x(:)); 0013 [xmx,mxi] = max(x(:)); 0014 0015 0016 return; 0017 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% TEST CODE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0019 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0020 % array = randn(2e6,1); 0021 % tic; [minval,maxval,minind,maxind] = CORE_minmax(array); t(1) = toc; 0022 % tic; [mnval,mnind] = min(array); [mxval,mxind] = max(array); t(2) = toc; 0023 % printf('CORE_minmax took %5.3f sec and equivalent native code took %5.3f sec.', t(1), t(2)); 0024 % if (~isequal([minval,maxval,minind,maxind], [mnval,maxval,mnind,mxind])) 0025 % printf('The two calls did not produce the same results.'); 0026 % end