Finding values with the same index in two arrays

36 ビュー (過去 30 日間)
Ben Whitby
Ben Whitby 2022 年 8 月 26 日
回答済み: the cyclist 2022 年 8 月 26 日
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

採用された回答

the cyclist
the cyclist 2022 年 8 月 26 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by