Common Elements in Two 2D Arrays

1 visualizzazione (ultimi 30 giorni)
Muhammad Adil
Muhammad Adil il 26 Ago 2023
Commentato: Stephen23 il 26 Ago 2023
Hello Dear All
A = [ 1 2 3 4 5 6;
3 1 2 4 5 7];
B = [ 1 1 3 5 6 7;
3 1 2 4 5 7];
I need Common (A, B) as
C = [1 3;
3 2]
Please Help!

Risposte (1)

Stephen23
Stephen23 il 26 Ago 2023
Modificato: Stephen23 il 26 Ago 2023
A = [1,2,3,4,5,6; 3,1,2,4,5,7]
A = 2×6
1 2 3 4 5 6 3 1 2 4 5 7
B = [1,1,3,5,6,7; 3,1,2,4,5,7]
B = 2×6
1 1 3 5 6 7 3 1 2 4 5 7
Method one: ALL and indexing:
X = all(A==B,1);
C = A(:,X)
C = 2×2
1 3 3 2
Method two: INTERSECT:
C = intersect(A.',B.','rows').'
C = 2×2
1 3 3 2
  2 Commenti
Muhammad Adil
Muhammad Adil il 26 Ago 2023
Thank you very much sir
Stephen23
Stephen23 il 26 Ago 2023
@Muhammad Adil: my pleasure. Please remember to click the accept button.

Accedi per commentare.

Categorie

Scopri di più su Operators and Elementary Operations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by