i have 2 array A and B and i need to check is item of B is available in A
i use this code but make error
code:
for k=1:length(B)
num=B(k)
r1=find(A==num)
if isempty (r1)
error
Index exceeds matrix dimensions.
Error in partiton1 (line 51)
if isempty (r1)

1 件のコメント

Walter Roberson
Walter Roberson 2017 年 1 月 26 日
You might possibly have created a variable named "isempty"

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

 採用された回答

Walter Roberson
Walter Roberson 2017 年 1 月 26 日

1 投票

A better way to check to see if an item in B is available in A is to use
if ismember(B(k), A)
If you are using floating point numbers, unless the numbers were copied from A into B or copied from B into A, then B(k) might not be exactly in A, because two floating point numbers calculated different ways might have different round-off. http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F . If you want to check to see if something "close enough" to B(k) is in A, then use ismembertol()

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Cell Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by