1

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.

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Damn. How did I miss this? Thank you so much. I must have used used 'unique' not less than a hundred times. Thanks again!
You're welcome. Using the third argument was something I needed to google... and I've used unique at least 200 times. :-) It's funny how you used the word "unique" in your question. Sometimes the answer is just hiding in plain sight. We all do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.