Finding values with the same index in two arrays

조회 수: 39 (최근 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 CenterFile Exchange에서 Creating 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