How to map a set of integer IDs to serial natural numbers?
6 views (last 30 days)
Show older comments
Hello,
I'm trying to map a set of IDs which are integers to a list of serial numbers. So, for example, the IDs are as follows:
[12 13 20 12 5 12 13]
then the output should be
[2 3 4 2 1 2 3]
Thus, 5 has been mapped to 1 and 20 has been mapped to 4.
Is there a clever and efficient way to accomplish this? I believe the command 'unique' should help, but I'm not able to find a way to use it.
0 Comments
Accepted Answer
Walter Roberson
on 7 Oct 2011
[u,a,b] = unique([12 13 20 12 5 12 13]);
and then b is the vector you want.
More Answers (0)
See Also
Categories
Find more on Language Support in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!