フィルターのクリア

How to select the first two (or first nth) rows of a matrix when the first and second elements of the rows always shows the same values fro more than two rows?

7 ビュー (過去 30 日間)
I have a matrix A with 3 columns and multiple rows,
A =
a_1 b_1 7
a_1 b_1 8
a_1 b_1 4
a_2 b_2 2
a_2 b_2 5
a_2 b_2 3
a_2 b_2 2
a_3 b_3 9
a_3 b_3 8
a_3 b_3 12
a_3 b_3 25
a_3 b_3 10
... ... ...
I would like to make another matrix B that contains the first two rows of each couple of parameter (a_i, b_i) in A , such that
B =
a_1 b_1 7
a_1 b_1 8
a_2 b_2 2
a_2 b_2 5
a_3 b_3 9
a_3 b_3 8
... ... ...
Note that the value a_i and b_i ae not unique, but each couple (a_i, b_i) would be different from (a_j, b_j).
Thanks in advance!

採用された回答

Matt J
Matt J 2022 年 2 月 14 日
編集済み: Matt J 2022 年 2 月 14 日
G=findgroups(A(:,1),A(:,2));
discard=cell2mat( splitapply(@(x){x(3:end,:)} , (1:numel(G))' ,G ) );
B=A;
B(discard,:)=[];

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by