How to remove duplicates in matrix with condition

2 ビュー (過去 30 日間)
Berk Gulmez
Berk Gulmez 2019 年 10 月 6 日
コメント済み: Berk Gulmez 2019 年 10 月 6 日
Hi everyone,
I just want to remove duplicates from NX2 matrices according to greatest value from column 2. for instance lets say we have 5x2 matrices;
X = [1 10;2 20;3 30;3 31;3 32]
at the result ı want to find
Xresult = [1 10;2 20;3 32]
So, I want to eliminate duplicates in "3" values and I want to see greatest "3" value in order to interpret my work.
Regards,

採用された回答

Bruno Luong
Bruno Luong 2019 年 10 月 6 日
X = [1 10;2 20;3 30;3 31;3 32];
Xs=sortrows(X);
[~,I]=unique(Xs(:,1),'last');
XResult = Xs(I,:)
  1 件のコメント
Berk Gulmez
Berk Gulmez 2019 年 10 月 6 日
thank you! This is exactly what I want.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by