Borrar filtros
Borrar filtros

Finding values with the same index in two arrays

46 visualizaciones (últimos 30 días)
Ben Whitby
Ben Whitby el 26 de Ag. de 2022
Respondida: the cyclist el 26 de Ag. de 2022
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

Respuesta aceptada

the cyclist
the cyclist el 26 de Ag. de 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.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by