anyEq

버전 1.3.0.0 (9.37 KB) 작성자: Jan
Fast check if 2 arrays have a common element
다운로드 수: 1.4K
업데이트 날짜: 2013/9/11

라이선스 보기

C-Mex: anyEq

This is a simple but fast check, if two arrays contain any common element.
The C-Mex is 25% to 60% 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 of any size. Complex or sparse array are rejected.
Types: DOUBLE, SINGLE, (U)INT8/16/32/64, CHAR, LOGICAL.
OUTPUT:
R: TRUE is replied if any element of X occurs in Y, FALSE otherwise.

NOTES:
- This is equivalent to:
R = any(X(:) == Y(1)) || any(X(:) == Y(2)) || ...
- This MEX version is faster than the Matlab method, because the creation of
the intermediate logical array is avoided:
Worst case (no matching element): 25% to 60% faster
Best case (first element matches): 99.99% faster for 1e6 elements
(Matlab 2011b/64, MSVC 2008).
- For small LOGICAL arrays (< 5'000 elements) anyEq is up to 65% slower than
any(X) or ~all(X). For larger arrays the speedup depends on the position of
the first match and can reach a factor of 7.
- X and Y are ordered automatically such, that the elements of the smaller
array are searched in the larger one.

EXAMPLES:
anyEq(0:0.1:1, 0.3) % FALSE: Effect of limited precision
anyEq(1:4, [5,2]) % TRUE: 2 is found in 1:4

COMPILATION: See anyEq.c for instructions how to compile the C-file.

TEST: Run uTest_anyEq to check validity and speed of the Mex function.

Tested: Matlab 6.5, 7.7, 7.8, 7.13, WinXP/32, Win7/64
Compiler: LCC2.4/3.8, BCC5.5, OWC1.8, MSVC2008/2010

Suggestion and bugreports by email or in the comment section are appreciated.

인용 양식

Jan (2024). anyEq (https://www.mathworks.com/matlabcentral/fileexchange/26867-anyeq), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2011b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.3.0.0

Accepts LOGICALs also.

1.2.0.0

Tested under 64 bit.

1.0.0.0