How to extract the months from a datetime table?
20 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ashfaq Ahmed
le 27 Fév 2023
Modifié(e) : Ashfaq Ahmed
le 27 Fév 2023
Hi!
I have a series of dates like this -
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1308710/image.png)
I want to create 12 variables naming - January, February, March, April,.., December in a way that each of the month contains the index value from the DateStamp for that month.
For example,
1984-05-02 is index 1, and it be assigned under 'May'.
Similarly, 1984-06-03 is index 2, and it be assigned under 'June'. And so on.
I have attached the DateStamp.mat file. Any feedback will be much appreciated! Thank you so much.
0 commentaires
Réponse acceptée
Stephen23
le 27 Fév 2023
Modifié(e) : Stephen23
le 27 Fév 2023
S = load('DateStamp.mat')
T = S.DateStamp;
T.month = T.date;
T.month.Format = 'MMMM'
But I am guessing that your actual goal is to perform some kind on analysis on your data, e.g. the means:
M = categorical(datetime(1,1,1,"Format","MMM")+calmonths(0:11));
T.year = T.date.Year;
T.month = M(T.date.Month).';
S = groupsummary(T,["year","month"],"mean","x_CloudCover");
U = unstack(S,"mean_x_CloudCover","month", "GroupingVariables","year")
4 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Dates and Time 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!