MATLAB: Give a id to same values in a cell

cell arrays

i have a cell with values
{'aa', 'aa', 'ab' ,'ab', 'ab', 'ac', ac', 'ad'};
now i want to give a number to same words eg:
[1 1 2 2 2 3 3 4];
please can someone help me…

Best Answer

You can use unique:
>> C = {'aa', 'aa', 'ab' ,'ab', 'ab', 'ac', 'ac', 'ad'};
>> [~,~,idx] = unique(C)
idx =
1 1 2 2 2 3 3 4
Related Question