Sort Timetable from May to April

1 vue (au cours des 30 derniers jours)
Jose Valles
Jose Valles le 27 Avr 2018
Commenté : Jose Valles le 30 Avr 2018
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

Réponse acceptée

Ameer Hamza
Ameer Hamza le 27 Avr 2018
Modifié(e) : Ameer Hamza le 27 Avr 2018
This line will do as required in question
newTable = [monthlyAvg(monthlyAvg.Properties.RowTimes(5:end), :); monthlyAvg(monthlyAvg.Properties.RowTimes(1:4), :)];
  1 commentaire
Jose Valles
Jose Valles le 30 Avr 2018
Thanks!! It works very well!

Connectez-vous pour commenter.

Plus de réponses (1)

Peter Perkins
Peter Perkins le 30 Avr 2018
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 commentaire
Jose Valles
Jose Valles le 30 Avr 2018
Thanks!! It also works very well!!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Language Fundamentals dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by