Reshaping an 1x365 matrix with daily observations within a year
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
dpb
el 4 de Mzo. de 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.
Respuestas (1)
Dennis
el 4 de Mzo. de 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 comentario
dpb
el 4 de Mzo. de 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.
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices 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!