Finding values with the same index in two arrays

33 views (last 30 days)
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

Accepted Answer

the cyclist
the cyclist on 26 Aug 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.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!