MATLAB Answers

Relabel data points to remove gaps

3 views (last 30 days)
Adam
Adam on 16 Mar 2018
Commented: Adam on 16 Mar 2018
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!

  0 Comments

Sign in to comment.

Accepted Answer

Birdman
Birdman on 16 Mar 2018
[~,~,idx]=unique(x)

  1 Comment

Adam
Adam on 16 Mar 2018
Thank you! That's very easy!

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!