how to index value falling particular interval

조회 수: 1 (최근 30일)
Jay Hanuman
Jay Hanuman 2016년 12월 22일
댓글: Guillaume 2016년 12월 22일
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.

채택된 답변

Guillaume
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
Jay Hanuman
Jay Hanuman 2016년 12월 22일
but interval should be 0-3,5-7,...,23-27, in above code it showing 0-4,5-8,,,,
Guillaume
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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by