Would be possible to calculate half hour average by using retime?

Hello,
The current time steps allowed in retime https://www.mathworks.com/help/matlab/ref/retime.html are:
'yearly' One year
'quarterly' One quarter
'monthly' One month
'weekly' One week
'daily' One day
'hourly' One hour
'minutely' One minute
'secondly' One second
But would be possible to calculate half hour average? or other specific time step average (like 5, 10, 15 minutes...) beside the standard here mentioned?
Thanks.

 採用された回答

Teja Muppirala
Teja Muppirala 2017 年 8 月 15 日

1 投票

Yes, there is an example a little bit down the in the documentation for RETIME , under this heading:
Interpolate Timetable Data to Arbitrary Times
I've copied the relevant sample code here:
%%Make sample data
Time = datetime({'2015-12-18 07:29:53';'2015-12-18 08:00:00';...
'2015-12-18 08:31:02';'2015-12-18 09:30:00'});
Temp = [37.3;41.9;45.7;39.8];
Pressure = [30.1;29.9;30.03;29.8];
TT1 = timetable(Time,Temp,Pressure)
%%Retime to 30 minute intervals
newTimes = [datetime('2015-12-18 07:30:00'):minutes(30):datetime('2015-12-18 09:30:00')];
TT2 = retime(TT1,newTimes,'linear')

4 件のコメント

Teja Muppirala
Teja Muppirala 2017 年 8 月 15 日
This example concerns interpolation, but aggregation works as well (for example, change 'linear' to 'mean').
Peter Perkins
Peter Perkins 2017 年 8 月 15 日
Teja is correct. Just to expand a bit, those strings like 'yearly', 'quarterly', etc. are just conveniences for common uses. You can synchronize to any time vector you want as long as it's increasing. Doesn't even have to be regular.
Robert
Robert 2017 年 8 月 15 日
Thank you, very appreciated Teja and Peter!
Peter Perkins
Peter Perkins 2018 年 7 月 5 日
Update: In R2018a, there's a new syntax that makes this a bit easier:
tt = retime(tt,'regular',method,'TimeStep',minutes(30))

サインインしてコメントする。

その他の回答 (1 件)

Ohad Zivan
Ohad Zivan 2018 年 7 月 5 日
編集済み: dpb 2019 年 5 月 30 日

1 投票

From Matlab: Adjust Timetable Data to Regular Times Calculate the means over six-hour time intervals. Specify a regular time step using the 'regular' input argument and the 'TimeStep' name-value pair argument.
TT = retime(outdoors,'regular','mean','TimeStep',hours(6)); TT(1:5,:) ans=5×3 timetable Time Humidity TemperatureF PressureHg _________________ ______ __________ ________
2015-11-15 00:00:00 48.9 51.45 29.61
2015-11-15 06:00:00 48.9 51.45 29.6
2015-11-15 12:00:00 49.025 51.45 29.61
2015-11-15 18:00:00 48.9 51.225 29.607
2015-11-16 00:00:00 48.5 51.4 29.61

カテゴリ

ヘルプ センター および File ExchangeTimetables についてさらに検索

質問済み:

2017 年 8 月 15 日

コメント済み:

2019 年 11 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by