Find specific rows of matrix that are subsets of other rows

3 visualizaciones (últimos 30 días)
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 comentarios
Jan
Jan el 28 de Feb. de 2013
Does subset mean inclusive or exclusive the edge? In other word, is [67,70] a subset of [65,70]?
ToLos Mil
ToLos Mil el 28 de Feb. de 2013
[67 70] is a subset of [65 70].

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 28 de Feb. de 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, :) = [];

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by