Code covered by the BSD License  

Highlights from
anyEq

Be the first to rate this file! 8 Downloads (last 30 days) File Size: 8.31 KB File ID: #26867
image thumbnail

anyEq

by Jan Simon

 

05 Mar 2010 (Updated 01 Nov 2011)

Fast check if 2 arrays have a common element

| Watch this File

File Information
Description

C-Mex: anyEq

This is a simple but fast check, if two arrays contain any common element.
If no common element is found, the C-Mex is 30% to 50% faster than the equivalent Matlab expression "any(X(:) == y)" and much faster than "any(ismember(X, Y))" if Y is an array.
If a matching element is found early, this function returns very fast without testing the rest.
In opposite to the Matlab version, the C-mex does not need any temporary arrays.

R = anyEq(X, Y)
INPUT:
  X, Y: Arrays, arbitrary size. The order of X and Y does not influence
        the speed. Types: DOUBLE, SINGLE, (U)INT8/16/32/64, CHAR.
OUTPUT:
  R: TRUE if X and Y have any common element.

Tested: Matlab 6.5, 2008a/b, 2009a, 2011b, 32/64 bit
LCC, BCC, OWC, MSVC 2008 and 2010, WinXP and Win7.
Assumed compatibility: Linux, MacOS.
Pre-compiled Mex: http://www.n-simon.de/mex

Suggestion and bugreports through the author page of the FEX or by email are appreciated.

MATLAB release MATLAB 7.8 (R2009a)
Other requirements Tested: Matlab 6.5, 7.7, 7.8, WinXP, 32 bit (64 bit assumed to work) Compiler: BCC5.5, LCC2.4/3.8, Open Watcom 1.8, MSVC++ 2008 Pre-compiled Mex: http://n-simon.de/mex
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
14 Jun 2010 Jan Simon

See also anyEceed: http://www.mathworks.com/matlabcentral/fileexchange/27857

14 Dec 2011 Jan Simon

For running the unit-test in Matlab 6.5 a replacement for the newer "cast" function is required:
function y = cast(x, t)
y = feval(t, x)

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

Tested under 64 bit.

Tag Activity for this File
Tag Applied By Date/Time
any Jan Simon 08 Mar 2010 12:28:57
equal Jan Simon 08 Mar 2010 12:28:57
isequal Jan Simon 08 Mar 2010 12:28:57
cmex Jan Simon 08 Mar 2010 12:28:57
common element Jan Simon 08 Mar 2010 12:28:57
compare Jan Simon 08 Mar 2010 12:28:57
ismember Jan Simon 02 Nov 2011 09:10:39

Contact us at files@mathworks.com