필터 지우기
필터 지우기

Reshaping an 1x365 matrix with daily observations within a year

조회 수: 5 (최근 30일)
GEORGIOS BEKAS
GEORGIOS BEKAS 2019년 3월 4일
댓글: dpb 2019년 3월 4일
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
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
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
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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2009b

Community Treasure Hunt

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

Start Hunting!

Translated by