フィルターのクリア

How can I find unique values in column ?

14 ビュー (過去 30 日間)
Selin Ozdemir
Selin Ozdemir 2016 年 5 月 1 日
編集済み: Azzi Abdelmalek 2016 年 5 月 1 日
This is my matrix
m=
1 10
2 1
2 2
2 3
2 4
3 1
3 2
3 3
5 1
5 2
5 4
6 2
I want to unique first column and second one can be anything among own values. I want to something like that
1 10
2 1
3 2
5 4
6 2
P.S I tried "unique" code it didnt work

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 5 月 1 日
編集済み: Azzi Abdelmalek 2016 年 5 月 1 日
[~,b]=unique(m(:,1),'stable')
out=m(b,:)
If you want to choose the second column randomly
[~,~,c]=unique(m(:,1),'stable')
ii=accumarray(c,(1:numel(c))',[],@(x) x(randi(numel(x))))
out=m(ii,:)
  1 件のコメント
Selin Ozdemir
Selin Ozdemir 2016 年 5 月 1 日
Thank you so much

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by