compare two arrays of different length ( inequality)

36 ビュー (過去 30 日間)
emar
emar 2017 年 6 月 1 日
コメント済み: emar 2017 年 6 月 1 日
Hello, I have two arrays with different length, for example A =[ 2 3 11 0 8 ] and B=[ 2 6 8] ( The data are bigger in the real case) and I want to compare them and find elements that verify abs(A(i)-B(j))> 2 .
Is there any fast function that do that (such ismember but for inequalities) ?
Thanks in advance

採用された回答

Walter Roberson
Walter Roberson 2017 年 6 月 1 日
R2016b and later syntax:
[i, j] = find( abs(A.' - B) > 2 );
Earlier releases:
[i, j] = find( abs(bsxfun(@minus, A.', B)) > 2 );
  1 件のコメント
emar
emar 2017 年 6 月 1 日
Thank you !

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

その他の回答 (1 件)

MathReallyWorks
MathReallyWorks 2017 年 6 月 1 日
Hello Elkhanssaa Marsali,
Firstly, make the length of A and B equal by adding extra zeros to the array who is shorter.
After you get the length of both array equal, try this code:
A=[2 3 11 0 8]
B=[2 6 8 0 0]
C=abs(A(:)-B(:))>2
You will get proper answer in terms of 1 and 0. Here, 1 means true and 0 means false
  1 件のコメント
emar
emar 2017 年 6 月 1 日
編集済み: emar 2017 年 6 月 1 日
Thank you for your answer. But the problem is that I want to verify the inequality for each element of A with all the elements of B ( so they will be 15 results ( true and false results) )

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

カテゴリ

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