How to find the index of a column data whose values are equal to another column data?

3 ビュー (過去 30 日間)
Leon
Leon 2021 年 3 月 14 日
コメント済み: Leon 2021 年 3 月 14 日
For example:
A = [31; 2; 57; 36; 87; 36];
B = [2; 36];
My goal is to find the inex of all the column A that are equal to any elements of B. In this case, the answer would be:
Ind = [0; 1; 0; 1; 0; 1];
For both A and B, I have extramely large number of rows, so it won't be efficient to write a loop. What is the most efficient way to performace this task?
Many thanks.

採用された回答

the cyclist
the cyclist 2021 年 3 月 14 日
A = [31; 2; 57; 36; 87; 36];
B = [2; 36];
Ind = ismember(A,B)
Ind = 6×1 logical array
0 1 0 1 0 1
  1 件のコメント
Leon
Leon 2021 年 3 月 14 日
Very cool. Glad to know there is a function specifically for that. Many thanks.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020b

Translated by