How do I replace multiple values with one value in a cell array
Afficher commentaires plus anciens
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
Réponses (1)
Jos (10584)
le 24 Juin 2016
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)
Catégories
En savoir plus sur Numeric Types dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!