- As the data is in “timetable” datatype and is continues. with no missing value, 24 entries in the table can be considered as a day.
- Loop through each day.
- Find the occurrences of maximum “TempC” value for that day.
- Store the values in a table.
- Output the desired table.
How to get daily max values of timetable keeping hour, using retime?
2 views (last 30 days)
Show older comments
Hi,
I have a hourly dataset in a timetable (data, attached as 'data.mat') and I need to take daily maximum values of one variable (TempC). Using retime I get
>> retime(data,'daily','max')
ans =
458×11 timetable
Data_CET DT_100m q R R2 RMSE SSE DFE TempC WindSpeed_kmh RainRate_mmh Rain_mm
________________ _______ ______ _______ _______ _______ ______ ___ ______ _____________ ____________ ________
01/06/2019 00:00 3.5271 24.942 0.71046 0.50476 1.2498 24.991 16 25.779 7.2908 0 0.011111
02/06/2019 00:00 3.0652 25.567 0.78203 0.61157 1.3609 29.634 16 25.949 10.935 0 0
03/06/2019 00:00 3.5115 24.56 0.78381 0.61435 1.1878 22.575 16 25.174 11.117 0 0
and so on. As you can see, time has days with the hour always 00:00. However, I need the hours to be kept, because I don't need only the maximum values, but else the hours at which they occurred. How can I achieve this? I thought to use find function to find the indexes of the values, but unfortunately there are some maximum values that occurred more than one time and so this method can't be applied.
Do you have any other ideas?
Thank you.
0 Comments
Answers (1)
Arun
on 19 Feb 2024
Hi Andrea,
I understand that you wish to get daily maximum for a variable value from a ‘timetable’ datatype. The requirement is to have hours value to be kept and “retime” function removes the time at which the maximum value occurs.
These are the steps that can create a table which contains daily maximum values with all the required fields:
Here is a sample code to implement the above-mentioned steps:
%convert the timetable into table.
load("data.mat")
datatable = timetable2table(data);
outputTable = table();
%loop through the day to find the time for maximum value of TempC
for i = 1:24:4416
extractValues = datatable(i:i+23,:);
maxValue = max(extractValues.TempC);
rowWithMaxTempC = extractValues.TempC == maxValue;
inOutputTable = extractValues(rowWithMaxTempC,:);
%store the value in the table
outputTable(end+1,:) = inOutputTable;
end
outputTable
This provides the required data, for daily maximum “TempC” with the time value as well.
For more information related to tables please refer the shared documentation link: https://www.mathworks.com/help/matlab/tables.html
I hope this helps you in resolving the issue.
0 Comments
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!