MATLAB: Give number to sequence

numbering to sequence

I have sequence
a=[17 56 42 12 12 99 102 45 76 76 41 99 12 45 56 17 76 86 125 160 36]
I want to do that give numbering to sequence starting from 1 i.e.minimum value is 12 so give it 1 then next value greater than 12 is 17 so give it 2 likewise so
a = [17 56 42 12 12 99 102 45 76 76 41 99 12 45 56 17 76 86 125 160 36]
a1 = [2 7 5 1 1 10 11 6 8 8 4 10 1 5 7 2 8 9 12 13 3]
how to do this.

Best Answer

Here's one semi-vectorized way:
a=[17 56 42 12 12 99 102 45 76 76 41 99 12 45 56 17 76 86 125 160 36]
uniquea = unique(a)
labels = 1 : length(uniquea)
for k = 1 : length(a)
index = find(a(k) == uniquea);
a1(k) = labels(index);
end