how to index value falling particular interval
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Jay Hanuman
el 22 de Dic. de 2016
Comentada: Guillaume
el 22 de Dic. de 2016
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 comentarios
Respuesta aceptada
Guillaume
el 22 de Dic. de 2016
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 comentarios
Guillaume
el 22 de Dic. de 2016
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!