How to find out the column number of a same element of one matrix in other matrix?

1 回表示 (過去 30 日間)
AS
AS 2019 年 1 月 17 日
コメント済み: AS 2019 年 1 月 18 日
If I have two different matrices, having some same element i.e. A=[23 45 6 7 89 12 3 6 7 8] and B=[6 7 45 12]. Now, in A and B some elements are same like 45, 6, 7 and 12. Now, I want to know/assign the column number of theses same elements (45, 6, 7 and 12) in A matrix. That means The column of each element of B in A matrix. Where the same elements are positioned (i.e. column) in matix A?

回答 (2 件)

madhan ravi
madhan ravi 2019 年 1 月 17 日
Position=find(ismember(A,B))

Walter Roberson
Walter Roberson 2019 年 1 月 17 日
[present, idx] = ismember(B, A);
present will be false for any element of B that is not in A. Otherwise B(K) == A(idx(K)) -- so idx is the entry number within A.
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 1 月 17 日
[present, idx] = ismember(B.', A.', 'rows');
AS
AS 2019 年 1 月 18 日
Accepted..
Thank you very much. This code is working properly.

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

カテゴリ

Help Center および File ExchangeDenoising and Compression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by