Effacer les filtres
Effacer les filtres

How do you make a matrix of months??

1 vue (au cours des 30 derniers jours)
Ern V
Ern V le 13 Oct 2016
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.

Réponses (2)

Walter Roberson
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.

Andrei Bobrov
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);

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by