Borrar filtros
Borrar filtros

Find order of increasing integers

2 visualizaciones (últimos 30 días)
Sebastian Daneli
Sebastian Daneli el 15 de Jun. de 2021
Comentada: Sebastian Daneli el 15 de Jun. de 2021
I have a vector
[3,4,8,9,10,13]
How can I sort this into
[3,4]; [8,9,10]; [13];
in an efficient way? I.e., split the parts of the vector where there is a linear increase of +1 from the previous entry.

Respuesta aceptada

Stephen23
Stephen23 el 15 de Jun. de 2021
Editada: Stephen23 el 15 de Jun. de 2021
V = [3,4,8,9,10,13];
D = diff(find([true,diff(V)~=1,true]));
C = mat2cell(V,1,D)
C = 1×3 cell array
{[3 4]} {[8 9 10]} {[13]}

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by