Sort Timetable from May to April
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Jose Valles
el 27 de Abr. de 2018
Comentada: Jose Valles
el 30 de Abr. de 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
0 comentarios
Respuesta aceptada
Ameer Hamza
el 27 de Abr. de 2018
Editada: Ameer Hamza
el 27 de Abr. de 2018
This line will do as required in question
newTable = [monthlyAvg(monthlyAvg.Properties.RowTimes(5:end), :); monthlyAvg(monthlyAvg.Properties.RowTimes(1:4), :)];
Más respuestas (1)
Peter Perkins
el 30 de Abr. de 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
Ver también
Categorías
Más información sobre Language Fundamentals en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!