I’m using MATLAB. I have a matrix with N elements filled with numbers [1; N], but there are only K unique number between them (K is much less than N). What is an efficient way to relabel the matrix so that it contains only numbers [1; K]? Equal numbers should become equal, and not equal should become not equal.
Example for N = 10, K = 4:
[1 4 8 9 4 1 8 9 4 1] -> [1 2 3 4 2 1 3 4 2 1]
- N ~ 1 000 000
- K ~ 10 000
Use the third output argument of
unique: