Intersection of two matrices based on 1st column

1 vue (au cours des 30 derniers jours)
Yasir Zahoor
Yasir Zahoor le 11 Fév 2019
Commenté : Yasir Zahoor le 11 Fév 2019
I have two matrices of with different number of columns but same number of rows (large data sets). Here is an exapmle.
A = [1 2 3; 4 5 6; 6 8 9];
B = [1 2 3 5; 4 6 7 8 ; 9 10 11 12];
I am looking to compare A and B on the basis of values in 1st column only and get an out put of the rows which are not common based on this criteria. Hence,
C = [ 9 10 11 12];
I have tried intersect with rows option but it needs same number of columns and secondly i dont have same values throught two rows (but only in the1st column) to work it properly.
  1 commentaire
Yasir Zahoor
Yasir Zahoor le 11 Fév 2019
Just to add, I would like to keep the order of the resultant rows intact.

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 11 Fév 2019
[~, rowstokeep] = setdiff(B(:, 1), A(:, 1)); %get index of rows in B whose 1st column is not in 1st column of A
C = B(rowstokeep, :)
  2 commentaires
Guillaume
Guillaume le 11 Fév 2019
Just to add, I would like to keep the order of the resultant rows intact.
Use the 'stable' option of setdiff, then.
Yasir Zahoor
Yasir Zahoor le 11 Fév 2019
thanx

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Types dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by