フィルターのクリア

Assign different strings in a cell array with a number

1 回表示 (過去 30 日間)
R2
R2 2015 年 4 月 23 日
回答済み: Ingrid 2015 年 4 月 23 日
I have a cell array that contains a lot of strings, where sometimes the string is repeated throughout the array. I want to assign a number to the different strings. So for example in my cell array I have names:
Harry
Jenny
Harry
Ben
So in this case Harry would be assigned the number 1 Jenny the number 2 and Ben the number 3. The probelm is that my cell array contains over a million names so I do not know what all of them are. Is there a way to create a code such that whenever the code comes across a new name it assigns it a number?
Thanks!

採用された回答

Ingrid
Ingrid 2015 年 4 月 23 日
maybe you could try using unique on the cell array so that you know all possible names. Then you could assign numbers to these names
lookupTable = unique({'a','b','c','d','a','b','e'});
then use this table as a look up to assign numbers according to the names. For more info you can look here http://www.mathworks.com/matlabcentral/answers/2015-find-index-of-cells-containing-my-string

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by