Sorting rows by a specific value

조회 수: 11 (최근 30일)
Richard Turner
Richard Turner 2021년 11월 3일
댓글: Richard Turner 2021년 11월 11일
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?

답변 (1개)

Cris LaPierre
Cris LaPierre 2021년 11월 3일
편집: Cris LaPierre 2021년 11월 3일
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
Richard Turner
Richard Turner 2021년 11월 11일
Thanks. I also managed to find a method by changing to an array and using circshift which worked well.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by