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!