Sort Timetable from May to April

조회 수: 4 (최근 30일)
Jose Valles
Jose Valles 2018년 4월 27일
댓글: Jose Valles 2018년 4월 30일
Hi,
I have the following timetable in MATLAB and I would like to sort the time rows from May to April instead of sorting the data from January to December. Is it possible to do it in MATLAB?
monthlyAvg =
12×3 timetable
T Month GroupCount nanmean_Atalaya
___ _____ __________ _______________
Jan 1 47 8.3085
Feb 2 47 7.3592
Mar 3 47 7.9989
Apr 4 47 6.9384
May 5 48 5.7711
Jun 6 48 8.9897
Jul 7 48 8.4933
Aug 8 48 10.84
Sep 9 48 16.269
Oct 10 48 12.142
Nov 11 48 9.7478
Dec 12 48 8.5193
Regards

채택된 답변

Ameer Hamza
Ameer Hamza 2018년 4월 27일
편집: Ameer Hamza 2018년 4월 27일
This line will do as required in question
newTable = [monthlyAvg(monthlyAvg.Properties.RowTimes(5:end), :); monthlyAvg(monthlyAvg.Properties.RowTimes(1:4), :)];
  댓글 수: 1
Jose Valles
Jose Valles 2018년 4월 30일
Thanks!! It works very well!

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

추가 답변 (1개)

Peter Perkins
Peter Perkins 2018년 4월 30일
As Ameer says, you can simply reorder the rows of the table, and if your table only ever has 12 rows, that's probably the way to go. But if May-Apr is consistently the way you want larger amounts of data ordered, you might consider making T an ordinal categorical with that ordering. It may not make sense for what you have, but just to demonstrate:
>> T = categorical((1:12)',[5:12 1:4],{'May' 'Jun' 'Jul' 'Aug' 'Sep' 'Oct' 'Nov' 'Dec' 'Jan' 'Feb' 'Mar' 'Apr'},'Ordinal',true)
T =
12×1 categorical array
Jan
Feb
Mar
[snip]
Nov
Dec
>> categories(T)
ans =
12×1 cell array
{'May'}
{'Jun'}
{'Jul'}
[snip]
{'Mar'}
{'Apr'}
>> monthlyAvg = table(T,rand(size(T)))
monthlyAvg =
12×2 table
T Var2
___ _______
Jan 0.81472
Feb 0.90579
Mar 0.12699
[snip]
Nov 0.15761
Dec 0.97059
>> sortrows(monthlyAvg,'T')
ans =
12×2 table
T Var2
___ _______
May 0.63236
Jun 0.09754
Jul 0.2785
Aug 0.54688
Sep 0.95751
Oct 0.96489
Nov 0.15761
Dec 0.97059
Jan 0.81472
Feb 0.90579
Mar 0.12699
Apr 0.91338
  댓글 수: 1
Jose Valles
Jose Valles 2018년 4월 30일
Thanks!! It also works very well!!

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

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by