Collapsing integer data into consecutive integers?
Mostrar comentarios más antiguos
I have a matrix of values that include integers >= 0. There are repeats, and also gaps in consecutiveness. I would like to collapse the data into consecutive integers, keeping the order intact.
Example: [ 0 1 4 4 1 5 8 1 4]
would go to
[ 0 1 2 2 1 3 4 1 2]
I can do this with loops and brute force, but I'm wondering if there's any quick way to do this since it is frequently called within a loop?
Thanks!
3 comentarios
John
el 18 de Jun. de 2013
I don't understand what you're aiming for... the example result you show isn't consecutive (1 to 3? 4 to 1?), and you're entirely changing some of the numbers.
John
el 18 de Jun. de 2013
It looks like you just divided everything by 2, rounding up.
Mark
el 18 de Jun. de 2013
Respuesta aceptada
Más respuestas (1)
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!