finding in which row two array has equal values

I have two array with different length A=(500.000,1) and B=(621,1) where all the 621 values of B are included in some of the A rows.
I want to find in which row of A, B will have the same value of A and create a new array C with the result(index)
any idea?

2 件のコメント

madhan ravi
madhan ravi 2019 年 4 月 17 日
編集済み: madhan ravi 2019 年 4 月 17 日
Illustrate with a short example. See if ismember() does what you want.
Bob Thompson
Bob Thompson 2019 年 4 月 17 日
ismember, find, or intersect might all be useful for you.

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

 採用された回答

Adam Danz
Adam Danz 2019 年 4 月 17 日
編集済み: Adam Danz 2019 年 4 月 17 日

1 投票

% Create fake data for the example
B = 1:621;
A = randi(621, 500000, 1);
% Loop through each element of B, return the row number of matching values in A
resultIdx = cell(size(B));
for i = 1:length(B)
resultIdx{i} = find(ismember(A,B(i)));
end
resultIdx{n} lists the rows of A that match the value of B(n).

1 件のコメント

Oxeley
Oxeley 2019 年 4 月 17 日
編集済み: Oxeley 2019 年 4 月 17 日
fantastic....ismember() it's could be the instruction that i've searched for a day .
thanks

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeOperators and Elementary Operations についてさらに検索

質問済み:

2019 年 4 月 17 日

編集済み:

2019 年 4 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by