check whether a number belongs to an array or not

1,672 ビュー (過去 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 日
ismember()
Note: if you are not using purely whole numbers, then please read http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
  5 件のコメント
biswajita lenka
biswajita lenka 2011 年 12 月 31 日
thanks,it works
Walter Roberson
Walter Roberson 2018 年 3 月 30 日
Note: later versions of MATLAB added ismembertol() for dealing with floating point numbers.

サインインしてコメントする。

その他の回答 (1 件)

Jan
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 件のコメント
ha ha
ha ha 2018 年 3 月 30 日
@Jan. Can you teach me how to run FEX: anyEq. as you mentioned? Thanks
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by