Effacer les filtres
Effacer les filtres

Finding the index of a matrix corresponding to a particular column of another matrix

1 vue (au cours des 30 derniers jours)
I have two matrices like, A= [4 12 ; 2 6] and B = [9 4 8 12 ; 2 2 4 6] I want get the relevant index of B corresponding to the 1st column in matrix A. (i.e- first column of A is 4 and 2. And the index corresponding to that in matrix A is index 2 )
  2 commentaires
madhan ravi
madhan ravi le 30 Oct 2018
Give an example of your desired result
Eranja Noopehewa
Eranja Noopehewa le 30 Oct 2018
Modifié(e) : Matt J le 30 Oct 2018
first column of A is 4 and 2. And the index corresponding to that column in matrix A is index 2

Connectez-vous pour commenter.

Réponse acceptée

Rik
Rik le 30 Oct 2018
You can try this:
A= [4 12 ; 2 6];
B = [9 4 8 12 ; 2 2 4 6];
selected_col=1;
col_in_B=find(all(A(:,selected_col)==B,1));

Plus de réponses (2)

madhan ravi
madhan ravi le 30 Oct 2018
A= [4 12 ; 2 6]
B = [9 4 8 12 ; 2 2 4 6]
idx=find(any(A(:,1)==B))
  4 commentaires

Connectez-vous pour commenter.


Matt J
Matt J le 30 Oct 2018
[~,idx]=ismember(A(:,1).',B.','rows')

Catégories

En savoir plus sur Matrix Indexing 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