Find monthly mean from daily data of same year using find function
조회 수: 1 (최근 30일)
이전 댓글 표시
채택된 답변
KSSV
2019년 7월 10일
REad about datevec. This will give you years, months and days. Using the months and your data you can find mean. Let thedates be your dates and A be your data.
[y,m,d] = datevec(thedates) ;
iwant = zeros(12,1) ;
for i = 1:12
iwant(i) = mean(A(m==i)) ;
end
댓글 수: 4
Guillaume
2019년 7월 10일
Well, I'm sorry to say but you're teaching beginners bad practices. As I said, your code will not work properly if the there is more than one year in the data.
And your code cannot be easily changed to aggregate the data per quarter or per week. Using retime, it's as trivial as specifying 'quarterly' or 'weekly' instead of 'monthly'. And the intent is of course much clearer.
추가 답변 (1개)
Guillaume
2019년 7월 10일
The easiest way:
data = readtimetable('C:\somewhere\somefile.xlsx'); %may need some adjustement depending on the actual format of the line
monthlydata = retime(data, 'monthly', 'mean');
Done!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!