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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by