Going back in time 1 week or a year
이전 댓글 표시
Dear all,
I attach a data set of weekly observations on an index.
Suppose that I am in week 2023/6/16 (yellow cell). For this cell I want to obtain the corresponding index value
Then I want to go back one week (7 days) ; that is to 2023/6/9 (yellow cell) and calculate its corresponding index value and then calculate the percentage change between the two values.
I used something like
t = datetime(2023,6,16);
t2 = dateshift(t,'dayofweek', 7,'previous')
but it does not work. I am sure that there is a mistake in my code. Is there a way to do that.
Also, assuming that we are in week 2023/6/16, I want to calculate the mean, min, max of the index values for the last 12 months. Is there a way to do that?
I would very much appreciate some guidance.
Thank you in advance!
채택된 답변
추가 답변 (1개)
Subtract the appropriate calendar duration.
t = datetime('today')
oneWeekAgo = t - calweeks(1)
oneYearAgo = t - calyears(1)
Don't try to subtract 1 year as a duration. That's 365.24 days, not exactly 1 year.
oneYearAgoAlmost = t - years(1)
카테고리
도움말 센터 및 File Exchange에서 Calendar에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!