How do I replace multiple values with one value in a cell array

I have an array of repeated values {14 13 11 2 2 3 1 7 8 36 etc.}. The values are from 1-38. I would like to replace ranges of values with one value. Such as all values 1-6 are replaced with a 1, values 7-14 are replaced with a 2 and so on. How would I go about doing this?
Thanks in advance for your help. Alan

Answers (1)

Do you need it to be a cell array? It would be easier if you converted it to a numerical array. You can use HISTC to assign bin numbers to each value, like this:
Acell = {14 13 11 2 2 3 1 7 8 36}
Anum = [Acell{:}] % convert to numeric array
[~, B] = histc(Anum,[0 6 14 21 28 33 38]+0.5)

Categories

Asked:

on 24 Jun 2016

Answered:

on 24 Jun 2016

Community Treasure Hunt

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

Start Hunting!