how to index value falling particular interval
1 次查看(过去 30 天)
显示 更早的评论
I have sequence of numbers [2 2 5 11 15 11 0 7 8 21 27 21 0 1 22 24 24 3 3 13 1 11 13] with min 0 and max 27 value. I want to divide values in intervals of size 4 i.e. 0-3,4-7,8-11,,,,24-27 and want to index particular value in which it falls. i.e. here 7 intervals. 2 falls in 1st interval so index as 1, 5 falls in 2nd interval so index as 2, so as follows
2 2 5 11 15 11 0 7 8....
1 1 2 3 4 3 1 2 3....
how to do it.
0 个评论
采纳的回答
Guillaume
2016-12-22
v = [2 2 5 11 15 11 0 7 8 21 27 21 0 1 22 24 24 3 3 13 1 11 13];
bins = min(v):4:max(v)+4;
[v; discretize(v, bins)]
2 个评论
Guillaume
2016-12-22
The intervals are 0 included to 4 non-included, so [0-4[, 4 included to 8 non-included, so [4-8[, etc. Considering integers, these are thus, 0-3 included, 4-7 included. Exactly as you asked, as can be seen from the output of my code that exactly matches what you asked.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!