Finding values with the same index in two arrays

38 visualizzazioni (ultimi 30 giorni)
Hi All,
I have two arrays that contain the row and column indices for values in a thrid array. Is there a way to compare the two matrices containg the indices and extract the indices that are common to both arrays.
Here is a simple example. I have two arrays: RowCol1 & RowCol2
RowCol1 = [17,487504; 17,487591; 17,487596; 17,487605; 17,487617]
RowCol2 = [16,113; 16,116; 16,244; 17,487591; 17,487596; 17,487605; 16,278]
I want to compare these two arrays and extract the row and column values that are common to both i.e. I want to extract
[17,487591; 17,487596; 17,487605;]
I appreciate any help.
thanks

Risposta accettata

the cyclist
the cyclist il 26 Ago 2022
RowCol1 = [17.487504; 17.487591; 17.487596; 17.487605; 17.487617];
RowCol2 = [16.113; 16.116; 16.244; 17.487591; 17.487596; 17.487605; 16.278];
out = intersect(RowCol1,RowCol2)
out = 3×1
17.4876 17.4876 17.4876
The default format doesn't show the differences, but those are the values you wanted.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by