フィルターのクリア

Find specific rows of matrix that are subsets of other rows

2 ビュー (過去 30 日間)
ToLos Mil
ToLos Mil 2013 年 2 月 28 日
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 件のコメント
Jan
Jan 2013 年 2 月 28 日
Does subset mean inclusive or exclusive the edge? In other word, is [67,70] a subset of [65,70]?
ToLos Mil
ToLos Mil 2013 年 2 月 28 日
[67 70] is a subset of [65 70].

サインインしてコメントする。

採用された回答

Jan
Jan 2013 年 2 月 28 日
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, :) = [];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by