Relabel data points to remove gaps

Hello,
I have an array of data points, which looks like this when sorted into ascending order.
x = [ 18 23 30 54 54 98];
There are gaps between consecutive entries there are possibly duplicates.
I would like to relabel the entries like this
x = [ 1 2 3 4 4 5];
A possibility would be a for loop with an increment, but is there a better way?
Thanks very much!

 採用された回答

Birdman
Birdman 2018 年 3 月 16 日

0 投票

[~,~,idx]=unique(x)

1 件のコメント

Adam
Adam 2018 年 3 月 16 日
Thank you! That's very easy!

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

その他の回答 (0 件)

製品

タグ

質問済み:

2018 年 3 月 16 日

コメント済み:

2018 年 3 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by