How do you make a matrix of months??
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, if for example you have a lot of dates like this, but a lot more:
727563
727564
727565
727566
727569
727570
727571
727572
727626
727627
727628
727629
727632
How can i sort them by month? I was trying to use reshape to make it a 30x12xyears matrix but he biggest problem that i found is that they dont have the same order, i mean some years have like 250 days and other with 260 so if i do reshape then im going to have some days in the incorrect month.
0 commentaires
Réponses (2)
Walter Roberson
le 13 Oct 2016
dv = datevec(YourSerialDateNums);
monthnum = dv(:,2);
grouped_by_month = accumarray(monthnum, YourSerialDateNums(:), [12 1], @(L) {L});
Now grouped_by_month will be a 12 x 1 cell array, one entry for each month, and the data stored there will be the entries from YourSerialDateNums that share that month number, in the same order as encountered in YourSerialDateNums. For example your posted data has entries from January, March, and June.
0 commentaires
Andrei Bobrov
le 13 Oct 2016
de = [727563
727564
727565
727566
727569
727570
727571
727572
727626
727627
727628
727629
727632];
[~,M] = datevec(de);
[~,ii] = sort(M);
out = de(ii);
0 commentaires
Voir également
Catégories
En savoir plus sur Logical 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!