Reputation: 53
I want to the do the following
Input: (cell array)
ab
ac
ad
aab
ac
aac
aab
ac
I want the output to map to unique numeric values, like
1
2
3
4
2
5
4
2
Is there an easy way to do this? The input is about 250,000 and of variable length. I just want to map the cells with the same content to the same number.
Thanks.
Upvotes: 1
Views: 166
Reputation: 46375
If we call your cell array A, then the following command does what you need:
[uniqueCells,~,idxYouWant] = unique(A);
In this, the uniqueCells
are the unique values you have (in sorted order); and idxYouWant
is an array of numbers like you want, where
A = uniqueCells(idxYouWant);
I think this is exactly what you need.
Upvotes: 5