MATLAB: Renaming values in an array

arrarenamevertcat

I have an array obtained by vertcat as follows:
B =
01C1
01C1
01C1
01C1
01C2
01C2
01C2
02C1
02C1
02C2
03C1
03C2
03C2
04C1
04C1
04C1
04C2
04C2
04C2
04C2
05C1
05C1
05C1
05C2
05C2
06C1
06C1
06C2
I want to replace the text with numbers with the following pattern:
01C1=1
01C2=2
02C1=3
02C2=4
03C1=5
04C2=6
and so on.
so my list would begin like:
1
1
1
1
2
2
2
3
3
etc..
Thanks for any help.

Best Answer

You can use unique to achieve this:
>> [~,~,ic] = unique(B,'rows')
ic =
1
1
1
1
2
2
2
3
3
4
5
...
Note that this method works only if the rows of B occur in the order of the pattern that you specify.