Sorting 2 row columns

I have two colums
for example
x=[0.5 0.8 0.9 0.9 0.9 1]
y=[2 1.8 1.6 1.5 1.2 1.1]
I want to obtain this result
x=[0.5 0.8 0.9 1]
y=[2 1.8 1.2 1.1]
The lowest y-value that occurs for the x-value (that occurs multiple times), needs to be sorted.

回答 (1 件)

Guillaume
Guillaume 2017 年 12 月 6 日

1 投票

[x, ~, id] = unique(x);
y = accumarray(id, y, [], @min)';

1 件のコメント

KL
KL 2017 年 12 月 6 日
+1! Simple and neat!

この質問は閉じられています。

タグ

質問済み:

2017 年 12 月 6 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by