Hello, I have a hourly meteorological data as attached. The first column is year, 2nd is month, 3rd is day, 4th is hour and the last is the value. I need to calculate the 30-day running mean from the hourly data and then subtract hourly data from the running mean values. Any help?

 Akzeptierte Antwort

KL
KL am 18 Aug. 2017
Bearbeitet: KL am 18 Aug. 2017

1 Stimme

dt = datetime([Yrly_slr(:,1:4) zeros(length(Yrly_slr),2)]);
TT = timetable(dt,Yrly_slr(:,5));
TT2 = retime(TT,'monthly','mean')
This is not a 30 day running mean but rather the monthly mean. I hope this is what you intended to do

4 Kommentare

Poulomi Ganguli
Poulomi Ganguli am 18 Aug. 2017
Hello, I don't want monthly mean. I need to calculate 30-day running mean and subtract them from hourly data. The final output will be time series anomaly = hrly data - 30-d running mean(hrly data);
KL
KL am 18 Aug. 2017
Bearbeitet: KL am 18 Aug. 2017
load('slr.mat')
newMat = reshape(Yrly_slr(:,5),30,floor(length(Yrly_slr)/30));
meanMat = repmat(mean(newMat,2),1,floor(length(Yrly_slr)/30));
res = newMat-meanMat;
Poulomi Ganguli
Poulomi Ganguli am 18 Aug. 2017
First of all, the value in column 5 are hourly values, so there are 24 hours in each day, if we reshape it to 30, it won't convert into 30-d value. I don't think the suggested code is correct. I will wait for some more suggestions. Thanks
KL
KL am 18 Aug. 2017
Bearbeitet: KL am 18 Aug. 2017
Yes, that's right but still the idea is the same with reshape!
load('slr.mat')
newMat = reshape(Yrly_slr(1:24*30*12,5),24*30,12);
meanMat = repmat(mean(newMat),24*30,1);
res = newMat-meanMat;

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Steven Lord
Steven Lord am 18 Aug. 2017

2 Stimmen

You might find the "Sample Points for Moving Average" example in the documentation for the movmean function to be of interest.
Nalini KS
Nalini KS am 19 Jun. 2020

0 Stimmen

How to do this for data having NaN values

Kategorien

Gefragt:

am 18 Aug. 2017

Beantwortet:

am 19 Jun. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by