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
답변 (1개)
Jos (10584)
2016년 6월 24일
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)
카테고리
도움말 센터 및 File Exchange에서 Numeric Types에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!