MATLAB Answers

check whether a number belongs to an array or not

조회 수: 4,692(최근 30일)
biswajita lenka
biswajita lenka 2011년 12월 28일
댓글: Walter Roberson 2018년 3월 30일
hi all, i want to check a number in the array.i have created an array and i want to know that a whether a perticular number belongs to the array or not. is there any inbuild function for "belongs to" in matlab. can anybody help me?

채택된 답변

Walter Roberson
Walter Roberson 2011년 12월 28일
Note: if you are not using purely whole numbers, then please read
  댓글 수: 5
Walter Roberson
Walter Roberson 2018년 3월 30일
Note: later versions of MATLAB added ismembertol() for dealing with floating point numbers.

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Jan 2011년 12월 28일
A = floor(rand(100, 100) * 1000);
contains5 = any(A(:) == 5);
If the array is large and the searched element is found early, Matlab wastes a lot of time by searching the rest of the array. Then this C-Mex is faster: FEX: anyEq.
  댓글 수: 4
James Tursa
James Tursa 2018년 3월 30일
- Download the code from the provided link
- Compile the code at the command line:
mex anyEq.c -largeArrayDims
- Use the function like any other function. For help on syntax,
help anyEq

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by