Sorting rows by a specific value

11 visualizaciones (últimos 30 días)
Richard Turner
Richard Turner el 3 de Nov. de 2021
Comentada: Richard Turner el 11 de Nov. de 2021
Hi, I have a table of data organized by month. The first column in the table is month and sorted in ascending order from 1>12. I'd like to sort the table starting at the current month e.g. current month = 10, so rows are sorted 10, 11,12,1,2....
Is there an easy way to do this with sortrows or similar?

Respuestas (1)

Cris LaPierre
Cris LaPierre el 3 de Nov. de 2021
Editada: Cris LaPierre el 3 de Nov. de 2021
There are a couple ways to do this. What works best depends on your data. You can use sortrows to sort your table keeping rows together.
Option 1 - add a year column, Sort by year then month. Use sortrows,
Option 2 - turn your month variable into a categorical, and define a category order using either the 'Ordinal',true name value pair or reordercats function. You can then sort using sortrows,
  1 comentario
Richard Turner
Richard Turner el 11 de Nov. de 2021
Thanks. I also managed to find a method by changing to an array and using circshift which worked well.

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Productos


Versión

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by