# How to extract specific rows from matrix by matching with other matrix?

3 vues (au cours des 30 derniers jours)
Emma Kuttler le 18 Fév 2022
Modifié(e) : Jan le 19 Fév 2022
I have two matrices. One is a two-column matrix of (i,j) pairs containing 1440 rows. The other matrix is 2878 rows, with the first two columns also containing some of the same (i,j) pairs and the other columns containing useful data. I'd like to produce a new matrix that only contains the (i,j) pairs from the smaller matrix with the corresponding data from the larger matrix. Essentially, i want to find matches from the small matrix in the large matrix and add only those rows to a new matrix. In the snips below, I'd like to output only the highlighted rows in the larger matrix, because those are a match for the smaller matrix.
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Walter Roberson le 18 Fév 2022
innerjoin() ?

Connectez-vous pour commenter.

### Réponse acceptée

Jan le 18 Fév 2022
Modifié(e) : Jan le 19 Fév 2022
match = ismember(LargerMatrix(:, 1:2), SmallerMatrix, 'rows');
Result = LargerMatrix(match, :);
[EDITED] Consider Walter's suggestion of innerjoin().
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

R2019b

### Community Treasure Hunt

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

Start Hunting!

Translated by