Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
AS
AS le 17 Jan 2019
Commenté : AS le 18 Jan 2019
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?

Réponses (2)

madhan ravi
madhan ravi le 17 Jan 2019
Position=find(ismember(A,B))

Walter Roberson
Walter Roberson le 17 Jan 2019
[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 commentaires
AS
AS le 18 Jan 2019
Accepted..
Thank you very much. This code is working properly.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by