Code covered by the BSD License  

Highlights from
anyExceed

Be the first to rate this file! 4 Downloads (last 30 days) File Size: 10.16 KB File ID: #27857
image thumbnail

anyExceed

by Jan Simon

 

09 Jun 2010 (Updated 01 Nov 2011)

Fast test for out of range elements, C-mex

| Watch this File

File Information
Description

Check if any element of an array exceeds an upper or lower limit

Equivalent Matlab expression:
  any(Array(:) < Lower) || any(Array(:) > Upper)
This Mex is 50% to 80% faster in the worst case (see screenshot):
1. It does not create temporary arrays.
2. It returns fast after the first exceeding element without processing the rest.
3. Infinite values can be ignored and the absolute values of the elements can be computed on the fly whithout the need of temporary arrays.

Flag = anyExceed(Array, Lower, Upper, Options...)
INPUT:
  Array: Array of any size. Accepted classes: DOUBLE, SINGLE, (U)INT8/16/32/64, CHAR.
  Lower, Upper: Scalar limits.
  Options: Optional strings to control the comparison. The options can be combined:
          'finite': +-Inf values in [Array] are ignored.
          'absolute': Compare absolute values.
          'exclude': Exclusive limits:
            Flag = any(Array(:) <= Lower) || any(Array(:) >= Upper)

OUTPUT:
  Flag: TRUE if any element exceeds the limits, FALSE otherwise.

EXAMPLES:
  anyExceed(rand(1000), 0, 1) % FALSE
  anyExceed(0:0.1:1, 0, 1, 'exclude') % TRUE
  anyExceed([1, Inf, 2], 0, 2, 'finite') % FALSE
  anyExceed(-10:10, 0, 10, 'abs') % FALSE
  anyExceed(-10:10, -1, 10, 'abs', 'ex') % TRUE

COMPILE:
  Windows: mex -O anyExceed.c
  Linux: mex -O CFLAGS="\$CFLAGS -std=C99" anyExceed.c
  Precompiled Mex: http://www.n-simon.de/mex
  See anyExceed.c for more information.
  Run uTest_anyExceed for a selftest.

Tested: Matlab 6.5, 2008a/b, 2009a, 2001b, 32/64 bit, WinXP, Win 7
LCC, BCC, OWC, MSVC 2008 and 2010
Assumed compatibility: Linux, OS-X

Comments and suggestions by email or as comments are appreciated.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
14 Jun 2010 Jan Simon

See also anyEq: http://www.mathworks.com/matlabcentral/fileexchange/26867

Please login to add a comment or rating.
Updates
01 Nov 2011

Tested under 2011b, 64bit.

Tag Activity for this File
Tag Applied By Date/Time
statistics Jan Simon 09 Jun 2010 13:06:24
data exploration Jan Simon 09 Jun 2010 13:06:24
cmex Jan Simon 09 Jun 2010 13:06:24
any Jan Simon 09 Jun 2010 13:06:24
exceed Jan Simon 09 Jun 2010 13:06:24
test Jan Simon 09 Jun 2010 13:06:24
range Jan Simon 09 Jun 2010 13:06:24
check Jan Simon 09 Jun 2010 13:06:24
limit Jan Simon 09 Jun 2010 13:06:24
compare Jan Simon 11 Jun 2010 03:51:30
absolute Jan Simon 11 Jun 2010 03:51:30

Contact us at files@mathworks.com