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

11 次查看(过去 30 天)
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by