give a id to same values in a cell

1 次查看(过去 30 天)
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...

采纳的回答

Stephen23
Stephen23 2016-5-30
编辑:Stephen23 2016-5-30
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by