# How to take an average over one month during different years ?

조회 수: 2 (최근 30일)
Ali Saremi 2017년 9월 1일
댓글: Kelly Kearney 2017년 9월 6일
Hi,
I've got some data from 1979 to 2017. I want to take an average over data of month, for example, January from 1979 to 2017. Only January, not other months. PLease see attached. I have also attached my Matlab file which contains the table with date and data. If you could take a look and let me know how I can do it, I would appreciate it. Thank you.
Regards Ali

댓글을 달려면 로그인하십시오.

### 채택된 답변

Kelly Kearney 2017년 9월 1일
A bit hard to tell from your screenshot whether your time array is an array of datetimes or an array of date strings. Assuming it's the former
% Some fake data
t = datetime(1979,1,1):datetime('today');
x = rand(size(t));
% Average data by month
for im = 1:12
xavg(im) = mean(x(month(t)==im));
end
##### 댓글 수: 3이전 댓글 1개 표시이전 댓글 1개 숨기기
Ali Saremi 2017년 9월 2일
Dear kelly,
I have also attached my MATLAB file. If you could take a look at this, would be great. Thank you.
Kind Regards Ali
Kelly Kearney 2017년 9월 6일
I don't see any attached mat file. If you post the exact code you attempted, and any error messages, that will be much more useful than screenshots to diagnose the problem.
In particular, is the Time column in your table composed of datetimes or date strings?

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by