Filter löschen
Filter löschen

Find specific rows of matrix that are subsets of other rows

2 Ansichten (letzte 30 Tage)
ToLos Mil
ToLos Mil am 28 Feb. 2013
Hello to all,
I am facing the following problem:
Let us assume that we have a matrix A = [2 10;15 20;50 60;65 70;61 64;16 18;66 69;67 68].
The elements of A(:,1) correspond to start times and the elements of A(:,2) to the end times of something. Thus, the elements of each row correspond to a closed set of values, for example row 1 corresponds to set [2 10].
I would like to find rows that are subsets of other rows and delete them. Specifically after the application of the requested procedure new matrix A_2 should be A_2 = [2 10;15 20;50 60;65 70;61 64], because last three rows of matrix A corresponded to subsets of rows 2 and 4.
I hope that i did explain the problem sufficiently.
  2 Kommentare
Jan
Jan am 28 Feb. 2013
Does subset mean inclusive or exclusive the edge? In other word, is [67,70] a subset of [65,70]?
ToLos Mil
ToLos Mil am 28 Feb. 2013
[67 70] is a subset of [65 70].

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 28 Feb. 2013
A = [2 10;15 20;50 60;65 70;61 64;16 18;66 69;67 68];
A1 = A(:, 1);
A2 = A(:, 2);
inside1 = bsxfun(@ge, A1, A1.') & bsxfun(@le, A1, A2.');
inside2 = bsxfun(@ge, A2, A1.') & bsxfun(@le, A2, A2.');
inside = inside1 & inside2;
inside(1:length(A1)+1:end) = false; % Clear main diagonal
toDelete = any(inside, 2);
A(toDelete, :) = [];

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing 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