Reshaping an 1x365 matrix with daily observations within a year
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
dpb
2019-3-4
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.
回答(1 个)
Dennis
2019-3-4
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 个评论
dpb
2019-3-4
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!