MATLAB Answers

How to convert daily data to monthly?

101 views (last 30 days)
Mohammad
Mohammad on 5 Dec 2012
Answered: ABHILASH SINGH on 13 Mar 2020
I have huge number of precipitation daily data in a column (say for 60 years) for 400 meteorological stations. Now I need to convert it to monthly. How can I do that? thanks.
  2 Comments
Mohammad
Mohammad on 5 Dec 2012
my data format is Year Month Day data
that is in 4 column. Length of month is always 30. Does it help for providing your answer? thanks.

Sign in to comment.

Answers (5)

Andrei Bobrov
Andrei Bobrov on 5 Dec 2012
Edited: Andrei Bobrov on 5 Dec 2012
one way
M - your data matrix with 4 columns < Year Month Day data > - double type
[a,~,c] = unique(M(:,1:2),'rows');
out = [a, accumarray(c,M(:,4),[],@mean)];

Chad Greene
Chad Greene on 5 Nov 2014
downsample_ts can do this by
precip_monthlymean = downsample_ts(precip_daily,t_daily);
  2 Comments
Chad Greene
Chad Greene on 31 Aug 2016
My mistake--
precip_monthlymean = downsample_ts(precip_daily,t_daily,'monthly','mean');

Sign in to comment.


Babak
Babak on 5 Dec 2012
Every 30 data rows, I would average them out and save it in 1 row.This way, 30 days shrinks down to 1 data (a month). Or another way, you can simply delete 29 data rows and keep only one from every 30 data rows.
  2 Comments
Babak
Babak on 5 Dec 2012
you need to write what your variables are and we would know which format they are... I mean what type they are for example, string? double, or cell? moreover they are all in a matrix or a cell or how you ahev sorted them..

Sign in to comment.


per isakson
per isakson on 5 Dec 2012
Edited: per isakson on 5 Dec 2012
Given thirty days in every month try this
daily_val = rand( 30*12, 1 );
daily_val = reshape( daily_val, 30, [] );
monthly_val = sum( daily_val, 1 );
here I assume that the first value in daily_val is the first value of a month. This is intended as a start.

Community Treasure Hunt

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

Start Hunting!