finding overlapping and non-overlapping values in matrix

조회 수: 19 (최근 30일)
NA
NA 2020년 3월 24일
답변: Birdman 2020년 3월 24일
I have
A = [3 16 4 16
3 21 4 21
3 29 3 29
17 27 18 29
25 72 26 72
61 70 61 70
62 63 62 63];
A(1,;) has overlap with A(2,:) and A(3,:)
A(2,:) has overlap with A(1,:) and A(3,:)
A(3,:) has overlap with A(1,:), A(3,:) and A(4,:)
A(4,:) has overlap with A(3,:)
A(5,:), A(6,:) and A(7,:) ---> do not have any intersection to others
result should be
overlapping_rows = [3 16 4 16
3 21 4 21
3 29 3 29
17 27 18 29]
non_overlapping_rows = [25 72 26 72
61 70 61 70
62 63 62 63]

채택된 답변

Birdman
Birdman 2020년 3월 24일
Try the following code:
A=[3 16 4 16;3 21 4 21;3 29 3 29;17 27 18 29;25 72 26 72;61 70 61 70;62 63 62 63];
Un=0;
for i=1:size(A,1)
idx{i}=setdiff(find(any(ismember(A,A(i,:)),2)),i);
if i>1
Un=union((idx{i}),Un);
end
end
Un=setdiff(Un,0);
overlapping_rows=A(Un,:)
non_overlapping_rows=A(setdiff(1:size(A,1),Un),:)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by