Reshaping an 1x365 matrix with daily observations within a year

3 vues (au cours des 30 derniers jours)
GEORGIOS BEKAS
GEORGIOS BEKAS le 4 Mar 2019
Commenté : dpb le 4 Mar 2019
I have a matrix with observations and its size is 1x365. It has to do with daily observations starting from the day Sunday, which is the first observation in the matrix.
I want to reshape the matrix with a form: Monday Tuesday Wednesday etc., which approximately is the equivalent of a 7x53 form (7 days, 53 weeks), but I can't find an exact match.
  1 commentaire
dpb
dpb le 4 Mar 2019
No can do...mod(365,7) --> 1 and you can't reshape() to a different number of elements.
You could augment time vector sufficiently with NaT values of the needed number before and after the first and last weeks of the particular year to match, but either that or using a cell array containing the particular data for given weekday would be about the only way to do such.
All in all, it's probably simpler to just use the data as serial datenum and find the desired dates to operate on computationally rather than trying to fiddle with the internal storage.

Connectez-vous pour commenter.

Réponses (1)

Dennis
Dennis le 4 Mar 2019
You could add some zeros/NaNs at the end of your 365 datapoints, then you should be able to reshape:
A=randi(100,365,1);
A(end+1:end+6)=NaN; %371/7=53
B=reshape(A,7,[]);
  1 commentaire
dpb
dpb le 4 Mar 2019
But, for only a very specific year will all those need to be at the beginning/end to start on a given day of the week...and, for general-purpose use, can't forget about leap years.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Calendar dans Help Center et File Exchange

Produits


Version

R2009b

Community Treasure Hunt

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

Start Hunting!

Translated by