finding overlapping and non-overlapping values in matrix

20 Ansichten (letzte 30 Tage)
NA
NA am 24 Mär. 2020
Beantwortet: Birdman am 24 Mär. 2020
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]

Akzeptierte Antwort

Birdman
Birdman am 24 Mär. 2020
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),:)

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by