Calculate the maximum and minimum values

Hello I have a big timetable I want to calculate the maximum and minimum values
Any ideas how to proceed?

1 Comment

To determine the maximum and minimum values of every month and the corresponding dates on which these values occurred, you can use the resample function in MATLAB. Here's an example of how you can use it:.
% Convert the timetable to a timetable with monthly intervals
monthlyData = retime(x, 'monthly', 'mean');
% Extract the maximum and minimum values of each month
MaxTemp = resample(x.Var, 'monthly', 'max');
MinTemp = resample(x.Var, 'monthly', 'min');
% Find the dates corresponding to the maximum and minimum values
MaxTempDates = resample(x.date_time, 'monthly', @(x) x(find(x.Var == max(x.Var), 1))); MinTempDates = resample(x.date_time, 'monthly', @(x) x(find(x.Var == min(x.Var), 1)));
In the code above, retime is used to convert the original timetable to a new timetable with monthly intervals. Then, resample is used to extract the maximum and minimum values of each month. Finally, resample is used again to find the dates corresponding to the maximum and minimum values. The @(x) x(find(x.Var == max(x.Var), 1)) and @(x) x(find(x.Var == min(x.Var), 1)) functions are used to find the first occurrence of the maximum and minimum values in each month, respectively. The resulting MaxTempDates and MinTempDates variables will be timetables with the date of the maximum and minimum values for each month.

Sign in to comment.

 Accepted Answer

I thought we covered a version of that in my Comment to your other thread.
That dealt with the hour that the daily maximum occurred. It would be straightforward to change that code to do what you want to do here.

24 Comments

can you be more specific?
It took a bit longer than I anticipated to adapt my previous code to this problem.
Try this —
DT = datetime('01-Dec-2022 00:00:00') + days(0:365).';
Temperature = sin(2*pi*(0:numel(DT)-1)/24-0.5).'*12+5 + randn(size(DT))*1.5;
TT1 = timetable(DT, Temperature)
TT1 = 366×1 timetable
DT Temperature ___________ ___________ 01-Dec-2022 0.66504 02-Dec-2022 1.5196 03-Dec-2022 5.691 04-Dec-2022 10.741 05-Dec-2022 10.712 06-Dec-2022 11.851 07-Dec-2022 15.96 08-Dec-2022 19.993 09-Dec-2022 17.681 10-Dec-2022 16.038 11-Dec-2022 15.199 12-Dec-2022 10.901 13-Dec-2022 13.714 14-Dec-2022 10.91 15-Dec-2022 3.3633 16-Dec-2022 2.7038
figure
plot(TT1.DT, TT1.Temperature)
grid
MonthlyMax = retime(TT1, 'monthly', 'max')
MonthlyMax = 13×1 timetable
DT Temperature ___________ ___________ 01-Dec-2022 19.993 01-Jan-2023 18.335 01-Feb-2023 18.99 01-Mar-2023 17.149 01-Apr-2023 18.211 01-May-2023 20.026 01-Jun-2023 17.665 01-Jul-2023 20.068 01-Aug-2023 18.648 01-Sep-2023 17.956 01-Oct-2023 16.865 01-Nov-2023 19.498 01-Dec-2023 14.852
DailyMax = retime(TT1, 'daily', 'max')
DailyMax = 366×1 timetable
DT Temperature ___________ ___________ 01-Dec-2022 0.66504 02-Dec-2022 1.5196 03-Dec-2022 5.691 04-Dec-2022 10.741 05-Dec-2022 10.712 06-Dec-2022 11.851 07-Dec-2022 15.96 08-Dec-2022 19.993 09-Dec-2022 17.681 10-Dec-2022 16.038 11-Dec-2022 15.199 12-Dec-2022 10.901 13-Dec-2022 13.714 14-Dec-2022 10.91 15-Dec-2022 3.3633 16-Dec-2022 2.7038
MonthlyMin = retime(TT1, 'monthly', 'min');
MonthlySTD = retime(TT1, 'monthly', @std);
T2 = table(MonthlyMax.DT, MonthlyMax.Temperature, MonthlyMin.Temperature, MonthlySTD.Temperature, 'VariableNames',{'DT','Max','Min','StDv'})
T2 = 13×4 table
DT Max Min StDv ___________ ______ _______ ______ 01-Dec-2022 19.993 -7.0232 8.0264 01-Jan-2023 18.335 -8.7917 8.6537 01-Feb-2023 18.99 -8.032 8.3328 01-Mar-2023 17.149 -7.717 8.5402 01-Apr-2023 18.211 -8.5859 8.0011 01-May-2023 20.026 -9.9484 8.9743 01-Jun-2023 17.665 -7.8864 8.6088 01-Jul-2023 20.068 -8.1143 8.6465 01-Aug-2023 18.648 -6.5155 8.789 01-Sep-2023 17.956 -8.7416 8.7519 01-Oct-2023 16.865 -9.2885 9.0736 01-Nov-2023 19.498 -8.6919 8.5491 01-Dec-2023 14.852 14.852 0
Thresholdv = [16; 17; 18; 19; 20]; % Column Vector
for k = 1:numel(Thresholdv)
DaysMeetingThreshold(k,:) = nnz(T2.Max >= Thresholdv(k)); % Days Equal To Or Higher Than Thresholdv (°C)
end
ThresholdTable = table(Thresholdv, DaysMeetingThreshold)
ThresholdTable = 5×2 table
Thresholdv DaysMeetingThreshold __________ ____________________ 16 12 17 11 18 8 19 4 20 2
[yd,md,dd] = ymd(DailyMax.DT); % Year, Month, Day Of Daily Maxima
for k = 1:numel(MonthlyMax)
[ym,mm,dm] = ymd(MonthlyMax.DT(k));
Lv = ismember([yd,md], [ym,mm], 'rows');
idx = DailyMax.Temperature(Lv) == MonthlyMax.Temperature(k);
Mv = find(Lv);
Dv = find(idx);
HM = DailyMax(Mv(Dv),:);
MonthDayMax(k,:) = timetable2table(HM);
end
MonthDayMax % Table Of Day In Each Month At Which Maximum Temperature Occurred
MonthDayMax = 13×2 table
DT Temperature ___________ ___________ 08-Dec-2022 19.993 03-Jan-2023 18.335 18-Feb-2023 18.99 15-Mar-2023 17.149 08-Apr-2023 18.211 01-May-2023 20.026 18-Jun-2023 17.665 11-Jul-2023 20.068 29-Aug-2023 18.648 22-Sep-2023 17.956 18-Oct-2023 16.865 11-Nov-2023 19.498 01-Dec-2023 14.852
.
There were duplicate maxima, and that caused the problem.
Changing this assignment to only select the first index:
HM = DailyMax(Mv(Dv(1)),:);
solved the problem.
I initially forgot the corresponding minima, so I added a separate loop for that. It is simply a duplicate of the first loop with appropriate changes.
Bothe the maxima and minima are now calculated.
% DT = datetime('01-Dec-2022 00:00:00') + days(0:365).';
% Temperature = sin(2*pi*(0:numel(DT)-1)/24-0.5).'*12+5 + randn(size(DT))*1.5;
% TT1 = timetable(DT, Temperature)
LD = load(websave('dataset','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1255052/dataset.mat'))
LD = struct with fields:
TT1: [513077×1 timetable]
TT1 = LD.TT1
TT1 = 513077×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 10.14 01-Jan-19 00:03:00 10.14 01-Jan-19 00:04:00 10.14 01-Jan-19 00:05:00 10.14 01-Jan-19 00:06:00 10.139 01-Jan-19 00:07:00 10.139 01-Jan-19 00:08:00 10.139 01-Jan-19 00:09:00 10.139 01-Jan-19 00:10:00 10.139 01-Jan-19 00:11:00 10.139 01-Jan-19 00:12:00 10.139 01-Jan-19 00:13:00 10.139 01-Jan-19 00:14:00 10.139 01-Jan-19 00:15:00 10.139 01-Jan-19 00:16:00 10.139 01-Jan-19 00:17:00 10.139
figure
plot(TT1.date_time, TT1.Temperature)
grid
% return
MonthlyMax = retime(TT1, 'monthly', 'max')
MonthlyMax = 12×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 10.241 01-Feb-19 00:00:00 10.278 01-Mar-19 00:00:00 10.269 01-Apr-19 00:00:00 10.261 01-May-19 00:00:00 10.204 01-Jun-19 00:00:00 10.204 01-Jul-19 00:00:00 10.184 01-Aug-19 00:00:00 10.175 01-Sep-19 00:00:00 10.223 01-Oct-19 00:00:00 10.231 01-Nov-19 00:00:00 10.212 01-Dec-19 00:00:00 10.292
DailyMax = retime(TT1, 'daily', 'max')
DailyMax = 365×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 10.18 02-Jan-19 00:00:00 10.174 03-Jan-19 00:00:00 10.139 04-Jan-19 00:00:00 10.182 05-Jan-19 00:00:00 10.166 06-Jan-19 00:00:00 10.162 07-Jan-19 00:00:00 10.221 08-Jan-19 00:00:00 10.233 09-Jan-19 00:00:00 10.184 10-Jan-19 00:00:00 10.109 11-Jan-19 00:00:00 10.152 12-Jan-19 00:00:00 10.119 13-Jan-19 00:00:00 10.12 14-Jan-19 00:00:00 10.084 15-Jan-19 00:00:00 10.189 16-Jan-19 00:00:00 10.241
DailyMin = retime(TT1, 'daily', 'min')
DailyMin = 365×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 10.134 02-Jan-19 00:00:00 10.083 03-Jan-19 00:00:00 10.05 04-Jan-19 00:00:00 10.137 05-Jan-19 00:00:00 10.138 06-Jan-19 00:00:00 10.122 07-Jan-19 00:00:00 10.161 08-Jan-19 00:00:00 10.183 09-Jan-19 00:00:00 10.006 10-Jan-19 00:00:00 10.01 11-Jan-19 00:00:00 10.109 12-Jan-19 00:00:00 10.077 13-Jan-19 00:00:00 10.084 14-Jan-19 00:00:00 10.002 15-Jan-19 00:00:00 10.006 16-Jan-19 00:00:00 10.19
MonthlyMin = retime(TT1, 'monthly', 'min');
MonthlySTD = retime(TT1, 'monthly', @std);
T2 = table(MonthlyMax.date_time, MonthlyMax.Temperature, MonthlyMin.Temperature, MonthlySTD.Temperature, 'VariableNames',{'date_time','Max','Min','StDv'})
T2 = 12×4 table
date_time Max Min StDv __________________ ______ ______ ________ 01-Jan-19 00:00:00 10.241 9.8976 NaN 01-Feb-19 00:00:00 10.278 10.053 0.049242 01-Mar-19 00:00:00 10.269 10.033 0.047355 01-Apr-19 00:00:00 10.261 10.027 0.052837 01-May-19 00:00:00 10.204 10.006 0.033589 01-Jun-19 00:00:00 10.204 10.051 0.024046 01-Jul-19 00:00:00 10.184 10.035 0.033762 01-Aug-19 00:00:00 10.175 10.061 0.027458 01-Sep-19 00:00:00 10.223 10.087 0.031658 01-Oct-19 00:00:00 10.231 10.041 0.043407 01-Nov-19 00:00:00 10.212 10.047 NaN 01-Dec-19 00:00:00 10.292 9.9079 NaN
Thresholdv = [16; 17; 18; 19; 20]; % Column Vector
for k = 1:numel(Thresholdv)
DaysMeetingThreshold(k,:) = nnz(T2.Max >= Thresholdv(k)); % Days Equal To Or Higher Than Thresholdv (°C)
end
ThresholdTable = table(Thresholdv, DaysMeetingThreshold)
ThresholdTable = 5×2 table
Thresholdv DaysMeetingThreshold __________ ____________________ 16 0 17 0 18 0 19 0 20 0
[ydx,mdx,ddx] = ymd(DailyMax.date_time); % Year, Month, Day Of Daily Maxima
for k = 1:numel(MonthlyMax)
[ym,mm,dm] = ymd(MonthlyMax.date_time(k));
Lv = ismember([ydx,mdx], [ym,mm], 'rows');
idx = DailyMax.Temperature(Lv) == MonthlyMax.Temperature(k);
Mv = find(Lv);
Dv = find(idx);
HM = DailyMax(Mv(Dv(1)),:);
MonthDayMax(k,:) = timetable2table(HM);
end
[ydn,mdn,ddn] = ymd(DailyMin.date_time); % Year, Month, Day Of Daily Maxima
for k = 1:numel(MonthlyMin)
[ym,mm,dm] = ymd(MonthlyMin.date_time(k));
Lv = ismember([ydn,mdn], [ym,mm], 'rows');
idx = DailyMin.Temperature(Lv) == MonthlyMin.Temperature(k);
Mv = find(Lv);
Dv = find(idx);
HM = DailyMin(Mv(Dv(1)),:);
MonthDayMin(k,:) = timetable2table(HM);
end
MonthDayMax % Table Of Day In Each Month At Which Maximum Temperature Occurred
MonthDayMax = 12×2 table
date_time Temperature __________________ ___________ 16-Jan-19 00:00:00 10.241 17-Feb-19 00:00:00 10.278 09-Mar-19 00:00:00 10.269 21-Apr-19 00:00:00 10.261 30-May-19 00:00:00 10.204 07-Jun-19 00:00:00 10.204 01-Jul-19 00:00:00 10.184 20-Aug-19 00:00:00 10.175 15-Sep-19 00:00:00 10.223 12-Oct-19 00:00:00 10.231 16-Nov-19 00:00:00 10.212 18-Dec-19 00:00:00 10.292
MonthDayMin % Table Of Day In Each Month At Which Minimum Temperature Occurred
MonthDayMin = 12×2 table
date_time Temperature __________________ ___________ 25-Jan-19 00:00:00 9.8976 06-Feb-19 00:00:00 10.053 12-Mar-19 00:00:00 10.033 06-Apr-19 00:00:00 10.027 05-May-19 00:00:00 10.006 29-Jun-19 00:00:00 10.051 10-Jul-19 00:00:00 10.035 03-Aug-19 00:00:00 10.061 05-Sep-19 00:00:00 10.087 04-Oct-19 00:00:00 10.041 26-Nov-19 00:00:00 10.047 14-Dec-19 00:00:00 9.9079
Are those the desired results?
.
I thought you only wanted the daily max and min.
This tweak gives the day and hour for the max and min each month —
% DT = datetime('01-Dec-2022 00:00:00') + days(0:365).';
% Temperature = sin(2*pi*(0:numel(DT)-1)/24-0.5).'*12+5 + randn(size(DT))*1.5;
% TT1 = timetable(DT, Temperature)
LD = load(websave('dataset','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1255052/dataset.mat'))
LD = struct with fields:
TT1: [513077×1 timetable]
TT1 = LD.TT1
TT1 = 513077×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 10.14 01-Jan-19 00:03:00 10.14 01-Jan-19 00:04:00 10.14 01-Jan-19 00:05:00 10.14 01-Jan-19 00:06:00 10.139 01-Jan-19 00:07:00 10.139 01-Jan-19 00:08:00 10.139 01-Jan-19 00:09:00 10.139 01-Jan-19 00:10:00 10.139 01-Jan-19 00:11:00 10.139 01-Jan-19 00:12:00 10.139 01-Jan-19 00:13:00 10.139 01-Jan-19 00:14:00 10.139 01-Jan-19 00:15:00 10.139 01-Jan-19 00:16:00 10.139 01-Jan-19 00:17:00 10.139
figure
plot(TT1.date_time, TT1.Temperature)
grid
% return
MonthlyMax = retime(TT1, 'monthly', 'max')
MonthlyMax = 12×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 10.241 01-Feb-19 00:00:00 10.278 01-Mar-19 00:00:00 10.269 01-Apr-19 00:00:00 10.261 01-May-19 00:00:00 10.204 01-Jun-19 00:00:00 10.204 01-Jul-19 00:00:00 10.184 01-Aug-19 00:00:00 10.175 01-Sep-19 00:00:00 10.223 01-Oct-19 00:00:00 10.231 01-Nov-19 00:00:00 10.212 01-Dec-19 00:00:00 10.292
MinutelyMax = retime(TT1, 'minutely', 'max')
MinutelyMax = 525600×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 10.14 01-Jan-19 00:01:00 NaN 01-Jan-19 00:02:00 NaN 01-Jan-19 00:03:00 10.14 01-Jan-19 00:04:00 10.14 01-Jan-19 00:05:00 10.14 01-Jan-19 00:06:00 10.139 01-Jan-19 00:07:00 10.139 01-Jan-19 00:08:00 10.139 01-Jan-19 00:09:00 10.139 01-Jan-19 00:10:00 10.139 01-Jan-19 00:11:00 10.139 01-Jan-19 00:12:00 10.139 01-Jan-19 00:13:00 10.139 01-Jan-19 00:14:00 10.139 01-Jan-19 00:15:00 10.139
MinutelyMin = retime(TT1, 'minutely', 'min')
MinutelyMin = 525600×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 10.14 01-Jan-19 00:01:00 NaN 01-Jan-19 00:02:00 NaN 01-Jan-19 00:03:00 10.14 01-Jan-19 00:04:00 10.14 01-Jan-19 00:05:00 10.14 01-Jan-19 00:06:00 10.139 01-Jan-19 00:07:00 10.139 01-Jan-19 00:08:00 10.139 01-Jan-19 00:09:00 10.139 01-Jan-19 00:10:00 10.139 01-Jan-19 00:11:00 10.139 01-Jan-19 00:12:00 10.139 01-Jan-19 00:13:00 10.139 01-Jan-19 00:14:00 10.139 01-Jan-19 00:15:00 10.139
MonthlyMin = retime(TT1, 'monthly', 'min');
MonthlySTD = retime(TT1, 'monthly', @std);
T2 = table(MonthlyMax.date_time, MonthlyMax.Temperature, MonthlyMin.Temperature, MonthlySTD.Temperature, 'VariableNames',{'date_time','Max','Min','StDv'})
T2 = 12×4 table
date_time Max Min StDv __________________ ______ ______ ________ 01-Jan-19 00:00:00 10.241 9.8976 NaN 01-Feb-19 00:00:00 10.278 10.053 0.049242 01-Mar-19 00:00:00 10.269 10.033 0.047355 01-Apr-19 00:00:00 10.261 10.027 0.052837 01-May-19 00:00:00 10.204 10.006 0.033589 01-Jun-19 00:00:00 10.204 10.051 0.024046 01-Jul-19 00:00:00 10.184 10.035 0.033762 01-Aug-19 00:00:00 10.175 10.061 0.027458 01-Sep-19 00:00:00 10.223 10.087 0.031658 01-Oct-19 00:00:00 10.231 10.041 0.043407 01-Nov-19 00:00:00 10.212 10.047 NaN 01-Dec-19 00:00:00 10.292 9.9079 NaN
Thresholdv = [16; 17; 18; 19; 20]; % Column Vector
for k = 1:numel(Thresholdv)
DaysMeetingThreshold(k,:) = nnz(T2.Max >= Thresholdv(k)); % Days Equal To Or Higher Than Thresholdv (°C)
end
ThresholdTable = table(Thresholdv, DaysMeetingThreshold)
ThresholdTable = 5×2 table
Thresholdv DaysMeetingThreshold __________ ____________________ 16 0 17 0 18 0 19 0 20 0
[yhx,mhx,dhx] = ymd(MinutelyMax.date_time); % Year, Month, Day Of Daily Maxima
for k = 1:numel(MonthlyMax)
[ym,mm,dm] = ymd(MonthlyMax.date_time(k));
Lv = ismember([yhx,mhx], [ym,mm], 'rows');
idx = MinutelyMax.Temperature(Lv) == MonthlyMax.Temperature(k);
Mv = find(Lv);
Dv = find(idx);
HM = MinutelyMax(Mv(Dv(1)),:);
MonthDayMax(k,:) = timetable2table(HM);
end
[yhn,mhn,dhn] = ymd(MinutelyMin.date_time); % Year, Month, Day Of Daily Maxima
for k = 1:numel(MonthlyMin)
[ym,mm,dm] = ymd(MonthlyMin.date_time(k));
Lv = ismember([yhn,mhn], [ym,mm], 'rows');
idx = MinutelyMin.Temperature(Lv) == MonthlyMin.Temperature(k);
Mv = find(Lv);
Dv = find(idx);
HM = MinutelyMin(Mv(Dv(1)),:);
MonthDayMin(k,:) = timetable2table(HM);
end
MonthDayMax % Table Of Day In Each Month At Which Maximum Temperature Occurred
MonthDayMax = 12×2 table
date_time Temperature __________________ ___________ 16-Jan-19 11:00:00 10.241 17-Feb-19 09:04:00 10.278 09-Mar-19 12:37:00 10.269 21-Apr-19 10:51:00 10.261 30-May-19 12:44:00 10.204 07-Jun-19 23:17:00 10.204 01-Jul-19 01:05:00 10.184 20-Aug-19 23:40:00 10.175 15-Sep-19 10:59:00 10.223 12-Oct-19 11:01:00 10.231 16-Nov-19 10:14:00 10.212 18-Dec-19 11:08:00 10.292
MonthDayMin % Table Of Day In Each Month At Which Minimum Temperature Occurred
MonthDayMin = 12×2 table
date_time Temperature __________________ ___________ 25-Jan-19 05:25:00 9.8976 06-Feb-19 03:51:00 10.053 12-Mar-19 17:53:00 10.033 06-Apr-19 04:59:00 10.027 05-May-19 06:00:00 10.006 29-Jun-19 18:16:00 10.051 10-Jul-19 19:30:00 10.035 03-Aug-19 19:13:00 10.061 05-Sep-19 16:02:00 10.087 04-Oct-19 05:41:00 10.041 26-Nov-19 01:46:00 10.047 14-Dec-19 07:12:00 9.9079
I kept the previous code intact, and copied everything to here to tweak it.
EDIT — (7 Jan 2023 at 17:20)
Changed ‘Hourly’ to ‘Minutely’ to get accuracy to the minute.
.
As always, my pleasure!
Yes! Improved.
.
Thank you!
That depends on how ‘3 max values and the 3 min values’ are defined. For the entire year, use maxk and mink. The second output will be the indices, so to get the entire row, do something like this —
T = array2table(randn(10,2))
T = 10×2 table
Var1 Var2 _________ _________ 0.034356 0.96346 -1.3018 2.0709 0.070568 -0.060068 0.67504 -1.4819 -1.0024 0.25872 -0.86488 1.3363 0.65376 0.51979 -0.093837 1.6005 -0.48581 -0.31631 0.77923 -0.74116
[Col1,idx] = maxk(T{:,1},3);
Tx3 = T(idx,:)
Tx3 = 3×2 table
Var1 Var2 _______ ________ 0.77923 -0.74116 0.67504 -1.4819 0.65376 0.51979
With respect to tweaking my code to do something similar, that could be possible, however not without a significant amount of recoding. The problem would be how to define the output table or timetable. That’s not immmediately obvious to me. The retime function would not work for this, however maxk and mink likely could.
With respect to using retime, one option could be:
retime(TT, 'minutely', @(x)maxk(x,3));
However that wouldn’t work in practice. The reason is that according to the documentation in the method section Aggregation Methods with respect to funciton handle methods, ‘Use the function specified by the function handle (for example, @std to calculate the standard deviation for the values in each time bin). func must return an output argument that is a scalar or a row vector, and must accept empty inputs.’ (emphasis added). So returning the 3 maxima would likely throw an error.
One way around that could be to first back up the original timetable, then run the code on a copy of it to first find the maximum for each month, save that, delete it from the timetable, run the code again, save that, delete the maxima, and repeat as long as necessary to return the desired numbers of maxima (or minima). The result would be as many output tables or timetables as required to get the required number of maxima (or minima).
.
Thank you!
As always, my pleasure!
That was a shile ago and I’ve forgotten what we were doing with it.
Try something like this —
LD = load(websave('dataset','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1255052/dataset.mat'));
TT1 = LD.TT1
TT1 = 513077×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 10.14 01-Jan-19 00:03:00 10.14 01-Jan-19 00:04:00 10.14 01-Jan-19 00:05:00 10.14 01-Jan-19 00:06:00 10.139 01-Jan-19 00:07:00 10.139 01-Jan-19 00:08:00 10.139 01-Jan-19 00:09:00 10.139 01-Jan-19 00:10:00 10.139 01-Jan-19 00:11:00 10.139 01-Jan-19 00:12:00 10.139 01-Jan-19 00:13:00 10.139 01-Jan-19 00:14:00 10.139 01-Jan-19 00:15:00 10.139 01-Jan-19 00:16:00 10.139 01-Jan-19 00:17:00 10.139
figure
plot(TT1.date_time, TT1.Temperature)
grid
Thresholdv = (9.8:0.1:10.4).'; % Column Vector
for k1 = 1:12
Lv = month(TT1.date_time) == k1; % Select Month
Month = retime(TT1(Lv,:),'daily','mean'); % Daily Mean Temperature
MMM{k1,:} = month(TT1(Lv,:).date_time(1),'shortname'); % For Row Names
for k2 = 1:numel(Thresholdv)-1 % Histogram Loop
Tempv = Month.Temperature;
DaysMeetingThreshold(k1,k2) = nnz((Tempv >= Thresholdv(k2)) & (Tempv < Thresholdv(k2+1))); % Days Equal To Or Higher Than Thresholdv (°C)
end
end
DaysThresholdTable = array2table(DaysMeetingThreshold, 'VariableNames',compose('%.2f',Thresholdv(1:end-1)), 'RowNames',[MMM{:}])
DaysThresholdTable = 12×6 table
9.80 9.90 10.00 10.10 10.20 10.30 ____ ____ _____ _____ _____ _____ Jan 0 3 11 14 3 0 Feb 0 0 1 14 13 0 Mar 0 0 2 21 8 0 Apr 0 0 5 20 5 0 May 0 0 3 28 0 0 Jun 0 0 0 30 0 0 Jul 0 0 11 20 0 0 Aug 0 0 6 25 0 0 Sep 0 0 0 25 5 0 Oct 0 0 3 20 8 0 Nov 0 0 5 25 0 0 Dec 0 2 6 10 13 0
This calculates a histogram of sorts without calling any histogram functions. I changed the code a bit to fit the actual data.
.
As always, my pleasure!
Perhaps —
MonthlyMean = retime(TT1,'monthly','mean')
That would seem to work (unless I am not understanding something).
I thought you wanted the mean.
For that, probably:
MonthlyMax = retime(TT1, 'monthly', 'max')
MonthlyMin = retime(TT1, 'monthly', 'min')
Then do the monthly range calculation from those, similar to the ‘DailyRange’ calculation.
I am a bit lost. The monthly range should be 12, not 365.
One way to do that would be to comkpare the month value in the ‘date_time’ variable with the months in a loop. Equate them, and then save those data to a different variable. Since I have no idea what you are doing at this point with the ‘MonthlyRange’ array, that is as precise as I can be. I hesitate to code with information I have no access to. There may be examples of that approach in code I have already written here.
.
it seems that we did versions of that already. Isn’t it possible to just adapt those to the current problem? It would likely be necessary to do the timing separately for the max, min, range, and any others, each in different timetable arrays, similarly to the approach in my previous Comment.
They would of necessity each have to be different timetable arrays, because I seriously doubt that the same times would be applicable to the various max, min, range, and others. The way timetable arrays work, they could not be combined into one timetable, although it might be possible to put the verious dates, times, max, min, range, and other datetime-variable arrays in the same table, providing that they all had the same (e.g. 12) row lengths. That would have to be coded separately and they would first have to be copied to table arrays after all the timetable arrays were calcualted.
I’m even more impressed with the table and timetable array types than I was previously!
In order to make it easier to get the exact times of the various maxima, minima, and the rest, I created a function ‘MonthlyToMinutely’ for that. It takes the 'monthly' and 'minutely' aggretated timetable arrays as arguments, and then returns a timetable with the exact times during the year that those values occurred in each month. It also checks to be certain that the timetable arguments have the same variables. It only works with timetable arrays with one variable, however that is what we are currently dealing with.
Here is an example of it with the 'min' timetable arrays —
LD = load(websave('dataset','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1255052/dataset.mat'));
TT1 = LD.TT1
TT1 = 513077×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 10.14 01-Jan-19 00:03:00 10.14 01-Jan-19 00:04:00 10.14 01-Jan-19 00:05:00 10.14 01-Jan-19 00:06:00 10.139 01-Jan-19 00:07:00 10.139 01-Jan-19 00:08:00 10.139 01-Jan-19 00:09:00 10.139 01-Jan-19 00:10:00 10.139 01-Jan-19 00:11:00 10.139 01-Jan-19 00:12:00 10.139 01-Jan-19 00:13:00 10.139 01-Jan-19 00:14:00 10.139 01-Jan-19 00:15:00 10.139 01-Jan-19 00:16:00 10.139 01-Jan-19 00:17:00 10.139
MinutelyMin = retime(TT1, 'minutely', 'min');
MonthlyMin = retime(TT1, 'monthly', 'min');
MonthDayMin = MonthlyToMinutely(MonthlyMin,MinutelyMin)
MonthDayMin = 12×2 table
date_time Temperature __________________ ___________ 25-Jan-19 05:25:00 9.8976 06-Feb-19 03:51:00 10.053 12-Mar-19 17:53:00 10.033 06-Apr-19 04:59:00 10.027 05-May-19 06:00:00 10.006 29-Jun-19 18:16:00 10.051 10-Jul-19 19:30:00 10.035 03-Aug-19 19:13:00 10.061 05-Sep-19 16:02:00 10.087 04-Oct-19 05:41:00 10.041 26-Nov-19 01:46:00 10.047 14-Dec-19 07:12:00 9.9079
function ExactTime = MonthlyToMinutely(MonthlyTT,MinutelyTT)
MinutelyVN = MinutelyTT.Properties.VariableNames;
MonthlyVN = MonthlyTT.Properties.VariableNames;
if ~strcmp(MinutelyVN{:}, MonthlyVN{:})
ExactTime = timetable();
fprintf('Variable names %s and %s in the argument timetables are not the same.',MonthlyVN{:},MinutelyVN{:})
return
end
[yhn,mhn,dhn] = ymd(MinutelyTT.date_time); % Year, Month, Day Of Daily Maxima
for k = 1:numel(MonthlyTT)
[ym,mm,dm] = ymd(MonthlyTT.date_time(k)); % Year, Month, Day Of Monthily Maxima
Lv = ismember([yhn,mhn], [ym,mm], 'rows');
idx = MinutelyTT{:,1}(Lv) == MonthlyTT{:,1}(k);
Mv = find(Lv);
Dv = find(idx);
HM = MinutelyTT(Mv(Dv(1)),:);
MonthDayTT(k,:) = timetable2table(HM);
end
ExactTime = MonthDayTT;
end
I did not test it with the others, however it should work with them.
.
Either save the function to a file called ‘MonthlyToMinutely.m’ (that is likely the best approach, and save it to a subdirectory on your MATLAB search path), or put it at the end of the script you are using it with, similar to what I did here. Saving it to a file is likely the easiest solution.
The code you would save to the ‘MonthlyToMinutely.m’ file is:
function ExactTime = MonthlyToMinutely(MonthlyTT,MinutelyTT)
MinutelyVN = MinutelyTT.Properties.VariableNames;
MonthlyVN = MonthlyTT.Properties.VariableNames;
if ~strcmp(MinutelyVN{:}, MonthlyVN{:})
ExactTime = timetable();
fprintf('Variable names %s and %s in the argument timetables are not the same.',MonthlyVN{:},MinutelyVN{:})
return
end
[yhn,mhn,dhn] = ymd(MinutelyTT.date_time); % Year, Month, Day Of Daily Maxima
for k = 1:numel(MonthlyTT)
[ym,mm,dm] = ymd(MonthlyTT.date_time(k)); % Year, Month, Day Of Monthily Maxima
Lv = ismember([yhn,mhn], [ym,mm], 'rows');
idx = MinutelyTT{:,1}(Lv) == MonthlyTT{:,1}(k);
Mv = find(Lv);
Dv = find(idx);
HM = MinutelyTT(Mv(Dv(1)),:);
MonthDayTT(k,:) = timetable2table(HM);
end
ExactTime = MonthDayTT;
end
.
I checked with the result in my earlier Comment.
They are not the same when I run it —
LD = load(websave('dataset','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1255052/dataset.mat'));
TT1 = LD.TT1
TT1 = 513077×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 10.14 01-Jan-19 00:03:00 10.14 01-Jan-19 00:04:00 10.14 01-Jan-19 00:05:00 10.14 01-Jan-19 00:06:00 10.139 01-Jan-19 00:07:00 10.139 01-Jan-19 00:08:00 10.139 01-Jan-19 00:09:00 10.139 01-Jan-19 00:10:00 10.139 01-Jan-19 00:11:00 10.139 01-Jan-19 00:12:00 10.139 01-Jan-19 00:13:00 10.139 01-Jan-19 00:14:00 10.139 01-Jan-19 00:15:00 10.139 01-Jan-19 00:16:00 10.139 01-Jan-19 00:17:00 10.139
MinutelyMax = retime(TT1, 'minutely', 'max');
MonthlyMax = retime(TT1, 'monthly', 'max');
MonthDayMax = MonthlyToMinutely(MonthlyMax,MinutelyMax)
MonthDayMax = 12×2 table
date_time Temperature __________________ ___________ 16-Jan-19 11:00:00 10.241 17-Feb-19 09:04:00 10.278 09-Mar-19 12:37:00 10.269 21-Apr-19 10:51:00 10.261 30-May-19 12:44:00 10.204 07-Jun-19 23:17:00 10.204 01-Jul-19 01:05:00 10.184 20-Aug-19 23:40:00 10.175 15-Sep-19 10:59:00 10.223 12-Oct-19 11:01:00 10.231 16-Nov-19 10:14:00 10.212 18-Dec-19 11:08:00 10.292
MinutelyMin = retime(TT1, 'minutely', 'min');
MonthlyMin = retime(TT1, 'monthly', 'min');
MonthDayMin = MonthlyToMinutely(MonthlyMin,MinutelyMin)
MonthDayMin = 12×2 table
date_time Temperature __________________ ___________ 25-Jan-19 05:25:00 9.8976 06-Feb-19 03:51:00 10.053 12-Mar-19 17:53:00 10.033 06-Apr-19 04:59:00 10.027 05-May-19 06:00:00 10.006 29-Jun-19 18:16:00 10.051 10-Jul-19 19:30:00 10.035 03-Aug-19 19:13:00 10.061 05-Sep-19 16:02:00 10.087 04-Oct-19 05:41:00 10.041 26-Nov-19 01:46:00 10.047 14-Dec-19 07:12:00 9.9079
MinutelyMax = retime(TT1, 'minutely', 'max');
MonthlyMax = retime(TT1, 'monthly', 'max');
MonthDayMax = MonthlyToMinutely(MonthlyMax,MinutelyMax)
MonthDayMax = 12×2 table
date_time Temperature __________________ ___________ 16-Jan-19 11:00:00 10.241 17-Feb-19 09:04:00 10.278 09-Mar-19 12:37:00 10.269 21-Apr-19 10:51:00 10.261 30-May-19 12:44:00 10.204 07-Jun-19 23:17:00 10.204 01-Jul-19 01:05:00 10.184 20-Aug-19 23:40:00 10.175 15-Sep-19 10:59:00 10.223 12-Oct-19 11:01:00 10.231 16-Nov-19 10:14:00 10.212 18-Dec-19 11:08:00 10.292
MinutelyMin = retime(TT1, 'minutely', 'min');
MonthlyMin = retime(TT1, 'monthly', 'min');
MonthDayMin = MonthlyToMinutely(MonthlyMin,MinutelyMin)
MonthDayMin = 12×2 table
date_time Temperature __________________ ___________ 25-Jan-19 05:25:00 9.8976 06-Feb-19 03:51:00 10.053 12-Mar-19 17:53:00 10.033 06-Apr-19 04:59:00 10.027 05-May-19 06:00:00 10.006 29-Jun-19 18:16:00 10.051 10-Jul-19 19:30:00 10.035 03-Aug-19 19:13:00 10.061 05-Sep-19 16:02:00 10.087 04-Oct-19 05:41:00 10.041 26-Nov-19 01:46:00 10.047 14-Dec-19 07:12:00 9.9079
function ExactTime = MonthlyToMinutely(MonthlyTT,MinutelyTT)
MinutelyVN = MinutelyTT.Properties.VariableNames;
MonthlyVN = MonthlyTT.Properties.VariableNames;
if ~strcmp(MinutelyVN{:}, MonthlyVN{:})
ExactTime = timetable();
fprintf('Variable names %s and %s in the argument timetables are not the same.',MonthlyVN{:},MinutelyVN{:})
return
end
[yhn,mhn,dhn] = ymd(MinutelyTT.date_time); % Year, Month, Day Of Daily Maxima
for k = 1:numel(MonthlyTT)
[ym,mm,dm] = ymd(MonthlyTT.date_time(k)); % Year, Month, Day Of Monthily Maxima
Lv = ismember([yhn,mhn], [ym,mm], 'rows');
idx = MinutelyTT{:,1}(Lv) == MonthlyTT{:,1}(k);
Mv = find(Lv);
Dv = find(idx);
HM = MinutelyTT(Mv(Dv(1)),:);
MonthDayTT(k,:) = timetable2table(HM);
end
ExactTime = MonthDayTT;
end
The function appears to work correctly.
.
To calculate the ranges, it would likely be better to calculate something other than the the minutely ranges and then the maximum and minimum ranges from that. A range will not work for the ‘minutely’ values, since there is only one temperature recorded each minute.
There is simply no possible way to calculate a range from single values, since there is no variation in them.
A fix for that is to aggregate over small intervals, and for this I chose:
'Timestep',minutes(2)
in ‘MinutelyMin’ and ‘MinutelyMax’ and from those I calculated the ranges. Other intervals are of course possible. The ‘Monthly’ range values were calcualted from the ‘Minutely’ values, since it is higholy unlikely that a monthly range is going to be in any way equivalent to a range over 2 minutes (or whatever aggregation interval is used). The reason of course is that the ranges are unique values, and do not exist in the original data. They first must be calculated.
With those changes, it works for the ranges —
LD = load(websave('dataset','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1255052/dataset.mat'));
TT1 = LD.TT1
TT1 = 513077×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 10.14 01-Jan-19 00:03:00 10.14 01-Jan-19 00:04:00 10.14 01-Jan-19 00:05:00 10.14 01-Jan-19 00:06:00 10.139 01-Jan-19 00:07:00 10.139 01-Jan-19 00:08:00 10.139 01-Jan-19 00:09:00 10.139 01-Jan-19 00:10:00 10.139 01-Jan-19 00:11:00 10.139 01-Jan-19 00:12:00 10.139 01-Jan-19 00:13:00 10.139 01-Jan-19 00:14:00 10.139 01-Jan-19 00:15:00 10.139 01-Jan-19 00:16:00 10.139 01-Jan-19 00:17:00 10.139
MinutelyMin = retime(TT1, 'regular', 'min', 'Timestep',minutes(2))
MinutelyMin = 262800×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 10.14 01-Jan-19 00:02:00 10.14 01-Jan-19 00:04:00 10.14 01-Jan-19 00:06:00 10.139 01-Jan-19 00:08:00 10.139 01-Jan-19 00:10:00 10.139 01-Jan-19 00:12:00 10.139 01-Jan-19 00:14:00 10.139 01-Jan-19 00:16:00 10.139 01-Jan-19 00:18:00 10.139 01-Jan-19 00:20:00 10.138 01-Jan-19 00:22:00 10.138 01-Jan-19 00:24:00 10.138 01-Jan-19 00:26:00 10.137 01-Jan-19 00:28:00 10.137 01-Jan-19 00:30:00 10.138
MinutelyMax = retime(TT1, 'regular', 'max', 'Timestep',minutes(2))
MinutelyMax = 262800×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 10.14 01-Jan-19 00:02:00 10.14 01-Jan-19 00:04:00 10.14 01-Jan-19 00:06:00 10.139 01-Jan-19 00:08:00 10.139 01-Jan-19 00:10:00 10.139 01-Jan-19 00:12:00 10.139 01-Jan-19 00:14:00 10.139 01-Jan-19 00:16:00 10.139 01-Jan-19 00:18:00 10.139 01-Jan-19 00:20:00 10.139 01-Jan-19 00:22:00 10.138 01-Jan-19 00:24:00 10.138 01-Jan-19 00:26:00 10.137 01-Jan-19 00:28:00 10.137 01-Jan-19 00:30:00 10.138
MinutelyRange = table(MinutelyMax.Temperature - MinutelyMin.Temperature, 'VariableNames',{'Temperature'});
MinutelyRange = addvars(MinutelyRange, MinutelyMin.date_time, 'Before','Temperature');
MinutelyRange.Properties.VariableNames = {'date_time','Temperature'};
MinutelyRange = table2timetable(MinutelyRange)
MinutelyRange = 262800×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 0 01-Jan-19 00:02:00 0 01-Jan-19 00:04:00 0.00018 01-Jan-19 00:06:00 0.00018 01-Jan-19 00:08:00 0.00036 01-Jan-19 00:10:00 0.00018 01-Jan-19 00:12:00 0.00037 01-Jan-19 00:14:00 0.00018 01-Jan-19 00:16:00 0.00018 01-Jan-19 00:18:00 0.00019 01-Jan-19 00:20:00 0.00055 01-Jan-19 00:22:00 0.00018 01-Jan-19 00:24:00 0.00037 01-Jan-19 00:26:00 0.00036 01-Jan-19 00:28:00 0 01-Jan-19 00:30:00 0.00018
MonthlyRangeMin = retime(MinutelyRange, 'monthly', 'min')
MonthlyRangeMin = 12×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 0 01-Feb-19 00:00:00 0 01-Mar-19 00:00:00 0 01-Apr-19 00:00:00 0 01-May-19 00:00:00 0 01-Jun-19 00:00:00 0 01-Jul-19 00:00:00 0 01-Aug-19 00:00:00 0 01-Sep-19 00:00:00 0 01-Oct-19 00:00:00 0 01-Nov-19 00:00:00 0 01-Dec-19 00:00:00 0
MonthlyRangeMax = retime(MinutelyRange, 'monthly', 'max')
MonthlyRangeMax = 12×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 0.00549 01-Feb-19 00:00:00 0.01117 01-Mar-19 00:00:00 0.03645 01-Apr-19 00:00:00 0.08332 01-May-19 00:00:00 0.00787 01-Jun-19 00:00:00 0.06977 01-Jul-19 00:00:00 0.00531 01-Aug-19 00:00:00 0.00385 01-Sep-19 00:00:00 0.04743 01-Oct-19 00:00:00 0.00933 01-Nov-19 00:00:00 0.01026 01-Dec-19 00:00:00 0.00751
MonthlyRange = table(MonthlyRangeMax.Temperature - MonthlyRangeMin.Temperature, 'VariableNames',{'Temperature'});
MonthlyRange = addvars(MonthlyRange, MonthlyRangeMin.date_time, 'Before','Temperature');
MonthlyRange.Properties.VariableNames = {'date_time','Temperature'};
MonthlyRange = table2timetable(MonthlyRange);
MonthDayRange = MonthlyToMinutely(MonthlyRange,MinutelyRange)
MonthDayRange = 12×2 table
date_time Temperature __________________ ___________ 25-Jan-19 04:20:00 0.00549 03-Feb-19 21:26:00 0.01117 22-Mar-19 09:36:00 0.03645 19-Apr-19 16:10:00 0.08332 25-May-19 06:56:00 0.00787 29-Jun-19 18:16:00 0.06977 18-Jul-19 13:52:00 0.00531 22-Aug-19 08:36:00 0.00385 14-Sep-19 11:48:00 0.04743 04-Oct-19 04:10:00 0.00933 07-Nov-19 18:44:00 0.01026 04-Dec-19 03:38:00 0.00751
function ExactTime = MonthlyToMinutely(MonthlyTT,MinutelyTT)
MinutelyVN = MinutelyTT.Properties.VariableNames;
MonthlyVN = MonthlyTT.Properties.VariableNames;
if ~strcmp(MinutelyVN{:}, MonthlyVN{:})
ExactTime = timetable();
fprintf('Variable names %s and %s in the argument timetables are not the same.',MonthlyVN{:},MinutelyVN{:})
return
end
[yhn,mhn,dhn] = ymd(MinutelyTT.date_time); % Year, Month, Day Of Daily Maxima
for k = 1:numel(MonthlyTT)
[ym,mm,dm] = ymd(MonthlyTT.date_time(k)); % Year, Month, Day Of Monthily Maxima
Lv = ismember([yhn,mhn], [ym,mm], 'rows');
idx = MinutelyTT{:,1}(Lv) == MonthlyTT{:,1}(k);
Mv = find(Lv);
Dv = find(idx);
HM = MinutelyTT(Mv(Dv(1)),:);
MonthDayTT(k,:) = timetable2table(HM);
end
ExactTime = MonthDayTT;
end
This is the only possible way to calculate the ranges in order to conform to the other calculations.
.
My pleasure!
The ‘MonthlyRangeMin’ and ‘MonthlyRangeMax’ default to midnight on the first of the month for the monthly values. That is simply how retime works. Similarly, the ‘Minutely’ values would default to zero seconds of the appropriate minute if seconds were reported.
The ‘MonthlyDayRange’ (or whatever you choose to call it, if different from my code) reports the dates and times —
MonthDayRange = 12×2 table
date_time Temperature
__________________ ___________
25-Jan-19 04:20:00 0.00549
03-Feb-19 21:26:00 0.01117
22-Mar-19 09:36:00 0.03645
19-Apr-19 16:10:00 0.08332
25-May-19 06:56:00 0.00787
29-Jun-19 18:16:00 0.06977
18-Jul-19 13:52:00 0.00531
22-Aug-19 08:36:00 0.00385
14-Sep-19 11:48:00 0.04743
04-Oct-19 04:10:00 0.00933
My ‘MonthlyToMinutely’ function turns out to be reasonably robust, so experiment with it with different arguments to get the result you want.
We used it earlier to get the hourly maxima and minima. The range values must be calculated from the 2-minute ranges (or whatever interval you choose) because the ranges are not an inherent part of the original data, that report single values only. The ranges must be calculated from them, although the accumulation interval for the ranges can be anything you want. I chose 2 minutes here because it is the shortest interval these data permit.
.
To the best of my knowledge, the aggregation time of the values for the range was not previously defined. For the daily range, this is straightforward.
Try this —
LD = load(websave('dataset','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1255052/dataset.mat'));
TT1 = LD.TT1
TT1 = 513077×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 10.14 01-Jan-19 00:03:00 10.14 01-Jan-19 00:04:00 10.14 01-Jan-19 00:05:00 10.14 01-Jan-19 00:06:00 10.139 01-Jan-19 00:07:00 10.139 01-Jan-19 00:08:00 10.139 01-Jan-19 00:09:00 10.139 01-Jan-19 00:10:00 10.139 01-Jan-19 00:11:00 10.139 01-Jan-19 00:12:00 10.139 01-Jan-19 00:13:00 10.139 01-Jan-19 00:14:00 10.139 01-Jan-19 00:15:00 10.139 01-Jan-19 00:16:00 10.139 01-Jan-19 00:17:00 10.139
% MinutelyMin = retime(TT1, 'regular', 'min', 'Timestep',minutes(2))
%
% MinutelyMax = retime(TT1, 'regular', 'max', 'Timestep',minutes(2))
%
% MinutelyRange = table(MinutelyMax.Temperature - MinutelyMin.Temperature, 'VariableNames',{'Temperature'});
% MinutelyRange = addvars(MinutelyRange, MinutelyMin.date_time, 'Before','Temperature');
% MinutelyRange.Properties.VariableNames = {'date_time','Temperature'};
% MinutelyRange = table2timetable(MinutelyRange)
DailyMin = retime(TT1, 'daily', 'min')
DailyMin = 365×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 10.134 02-Jan-19 00:00:00 10.083 03-Jan-19 00:00:00 10.05 04-Jan-19 00:00:00 10.137 05-Jan-19 00:00:00 10.138 06-Jan-19 00:00:00 10.122 07-Jan-19 00:00:00 10.161 08-Jan-19 00:00:00 10.183 09-Jan-19 00:00:00 10.006 10-Jan-19 00:00:00 10.01 11-Jan-19 00:00:00 10.109 12-Jan-19 00:00:00 10.077 13-Jan-19 00:00:00 10.084 14-Jan-19 00:00:00 10.002 15-Jan-19 00:00:00 10.006 16-Jan-19 00:00:00 10.19
DailyMax = retime(TT1, 'daily', 'max')
DailyMax = 365×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 10.18 02-Jan-19 00:00:00 10.174 03-Jan-19 00:00:00 10.139 04-Jan-19 00:00:00 10.182 05-Jan-19 00:00:00 10.166 06-Jan-19 00:00:00 10.162 07-Jan-19 00:00:00 10.221 08-Jan-19 00:00:00 10.233 09-Jan-19 00:00:00 10.184 10-Jan-19 00:00:00 10.109 11-Jan-19 00:00:00 10.152 12-Jan-19 00:00:00 10.119 13-Jan-19 00:00:00 10.12 14-Jan-19 00:00:00 10.084 15-Jan-19 00:00:00 10.189 16-Jan-19 00:00:00 10.241
DailyRange = table2timetable(table(DailyMin.date_time, DailyMax.Temperature - DailyMin.Temperature, 'VariableNames',{'date_time','Temperature'}))
DailyRange = 365×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 0.04597 02-Jan-19 00:00:00 0.09137 03-Jan-19 00:00:00 0.089 04-Jan-19 00:00:00 0.04504 05-Jan-19 00:00:00 0.02765 06-Jan-19 00:00:00 0.04029 07-Jan-19 00:00:00 0.06061 08-Jan-19 00:00:00 0.05054 09-Jan-19 00:00:00 0.17799 10-Jan-19 00:00:00 0.09925 11-Jan-19 00:00:00 0.04321 12-Jan-19 00:00:00 0.04194 13-Jan-19 00:00:00 0.03571 14-Jan-19 00:00:00 0.08241 15-Jan-19 00:00:00 0.18275 16-Jan-19 00:00:00 0.051641
MonthlyRangeMin = retime(DailyRange, 'monthly', 'min')
MonthlyRangeMin = 12×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 0.01758 01-Feb-19 00:00:00 0.01977 01-Mar-19 00:00:00 0.02014 01-Apr-19 00:00:00 0.01721 01-May-19 00:00:00 0.01703 01-Jun-19 00:00:00 0.01629 01-Jul-19 00:00:00 0.01703 01-Aug-19 00:00:00 0.01135 01-Sep-19 00:00:00 0.01373 01-Oct-19 00:00:00 0.01593 01-Nov-19 00:00:00 0.00751 01-Dec-19 00:00:00 0.01722
MonthlyRangeMax = retime(DailyRange, 'monthly', 'max')
MonthlyRangeMax = 12×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 0.18275 01-Feb-19 00:00:00 0.11226 01-Mar-19 00:00:00 0.09815 01-Apr-19 00:00:00 0.09944 01-May-19 00:00:00 0.10896 01-Jun-19 00:00:00 0.09028 01-Jul-19 00:00:00 0.08588 01-Aug-19 00:00:00 0.052 01-Sep-19 00:00:00 0.06117 01-Oct-19 00:00:00 0.1335 01-Nov-19 00:00:00 0.11464 01-Dec-19 00:00:00 0.17781
% MonthlyRange = table(MonthlyRangeMax.Temperature - MonthlyRangeMin.Temperature, 'VariableNames',{'Temperature'});
% MonthlyRange = addvars(MonthlyRange, MonthlyRangeMin.date_time, 'Before','Temperature');
% MonthlyRange.Properties.VariableNames = {'date_time','Temperature'};
% MonthlyRange = table2timetable(MonthlyRange)
MonthDayRangeMax = MonthlyToMinutely(MonthlyRangeMax,DailyRange) % Output: Day In Month With Maximum Range
MonthDayRangeMax = 12×2 table
date_time Temperature __________________ ___________ 15-Jan-19 00:00:00 0.18275 11-Feb-19 00:00:00 0.11226 11-Mar-19 00:00:00 0.09815 19-Apr-19 00:00:00 0.09944 04-May-19 00:00:00 0.10896 29-Jun-19 00:00:00 0.09028 10-Jul-19 00:00:00 0.08588 03-Aug-19 00:00:00 0.052 24-Sep-19 00:00:00 0.06117 08-Oct-19 00:00:00 0.1335 24-Nov-19 00:00:00 0.11464 14-Dec-19 00:00:00 0.17781
MonthDayRangeMin = MonthlyToMinutely(MonthlyRangeMin,DailyRange) % Output: Day In Month With Mionimum Range
MonthDayRangeMin = 12×2 table
date_time Temperature __________________ ___________ 21-Jan-19 00:00:00 0.01758 19-Feb-19 00:00:00 0.01977 07-Mar-19 00:00:00 0.02014 11-Apr-19 00:00:00 0.01721 01-May-19 00:00:00 0.01703 03-Jun-19 00:00:00 0.01629 21-Jul-19 00:00:00 0.01703 19-Aug-19 00:00:00 0.01135 08-Sep-19 00:00:00 0.01373 30-Oct-19 00:00:00 0.01593 25-Nov-19 00:00:00 0.00751 17-Dec-19 00:00:00 0.01722
function ExactTime = MonthlyToMinutely(MonthlyTT,MinutelyTT) % FUNCTION: 'MonthlyToMinutely'
MinutelyVN = MinutelyTT.Properties.VariableNames;
MonthlyVN = MonthlyTT.Properties.VariableNames;
if ~strcmp(MinutelyVN{:}, MonthlyVN{:})
ExactTime = timetable();
fprintf('Variable names %s and %s in the argument timetables are not the same.',MonthlyVN{:},MinutelyVN{:})
return
end
[yhn,mhn,dhn] = ymd(MinutelyTT.date_time); % Year, Month, Day Of Daily Maxima
for k = 1:numel(MonthlyTT)
[ym,mm,dm] = ymd(MonthlyTT.date_time(k)); % Year, Month, Day Of Monthily Maxima
Lv = ismember([yhn,mhn], [ym,mm], 'rows');
idx = MinutelyTT{:,1}(Lv) == MonthlyTT{:,1}(k);
Mv = find(Lv);
Dv = find(idx);
HM = MinutelyTT(Mv(Dv(1)),:);
MonthDayTT(k,:) = timetable2table(HM);
end
ExactTime = MonthDayTT;
end
The times are all at midnight (00:00:00) because the ranges are now daily. The retime function defaults to midnight for daily aggregation.
And again, ‘MonthlyToMinuitely’ works here and gives the correct result!
.
For a daily range (over 24 hours), the hour and minute are not defined. You can calculate a daily maximum and daily minimum and get those times (I believe we already did that a while ago), however they will by definition not be the same times, so there will not be any one specific time for the range.
Probably the best you can do is to store the times for the maximum and minimum for a specific day and the times they occurred, and save them each in single rows for each day (and the range, if desired, as a separate variable) in a separate table (not a timetable, since it requires a single time vector). We already did those calculations, and I have examples of how to create that sort of table in the code I already posted, although not in that exact format.
Because you wanted the hour and minute, I initially defined the range over consecutive 2-minute intervals.
I am slightly lost. I have no idea where we are with this data set.
My guess is that we’re doing this —
LD = load(websave('T','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1289405/T.mat'));
TT1 = LD.T
TT1 = 513077×1 timetable
date_time Wind __________________ ______ 01-Jan-19 00:00:00 -5.624 01-Jan-19 00:03:00 -5.624 01-Jan-19 00:04:00 -5.818 01-Jan-19 00:05:00 -5.818 01-Jan-19 00:06:00 -6.012 01-Jan-19 00:07:00 -6.206 01-Jan-19 00:08:00 -6.788 01-Jan-19 00:09:00 -5.818 01-Jan-19 00:10:00 -5.43 01-Jan-19 00:11:00 -5.818 01-Jan-19 00:12:00 -6.012 01-Jan-19 00:13:00 -5.43 01-Jan-19 00:14:00 -6.012 01-Jan-19 00:15:00 -5.236 01-Jan-19 00:16:00 -5.818 01-Jan-19 00:17:00 -6.206
% return
% LD = load(websave('dataset','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1255052/dataset.mat'));
% TT1 = LD.TT1
MinutelyMax = retime(TT1, 'minutely', 'max');
MonthlyMax = retime(TT1, 'monthly', 'max');
MonthDayMax = MonthlyToMinutely(MonthlyMax,MinutelyMax)
MonthDayMax = 12×2 table
date_time Wind __________________ ______ 28-Jan-19 12:48:00 783.79 13-Feb-19 13:23:00 894.92 29-Mar-19 12:24:00 1023.9 11-Apr-19 13:17:00 1214 30-May-19 13:29:00 1280.9 29-Jun-19 14:46:00 1123.2 14-Jul-19 13:46:00 1132.7 04-Aug-19 13:57:00 966.11 03-Sep-19 12:45:00 1053.8 02-Oct-19 13:54:00 946.32 08-Nov-19 11:50:00 777 13-Dec-19 12:18:00 738.4
MinutelyMin = retime(TT1, 'minutely', 'min');
MonthlyMin = retime(TT1, 'monthly', 'min');
MonthDayMin = MonthlyToMinutely(MonthlyMin,MinutelyMin)
MonthDayMin = 12×2 table
date_time Wind __________________ _______ 11-Jan-19 22:59:00 -15.904 23-Feb-19 22:45:00 -13.189 27-Mar-19 23:36:00 -12.413 23-Apr-19 19:17:00 -18.232 04-May-19 21:30:00 -18.813 29-Jun-19 01:59:00 -16.68 10-Jul-19 21:13:00 -18.426 29-Aug-19 04:04:00 -7.952 14-Sep-19 06:08:00 -9.697 06-Oct-19 00:50:00 -19.589 17-Nov-19 21:04:00 -17.65 26-Dec-19 17:52:00 -18.62
MinutelyMax = retime(TT1, 'minutely', 'max');
MonthlyMax = retime(TT1, 'monthly', 'max');
MonthDayMax = MonthlyToMinutely(MonthlyMax,MinutelyMax)
MonthDayMax = 12×2 table
date_time Wind __________________ ______ 28-Jan-19 12:48:00 783.79 13-Feb-19 13:23:00 894.92 29-Mar-19 12:24:00 1023.9 11-Apr-19 13:17:00 1214 30-May-19 13:29:00 1280.9 29-Jun-19 14:46:00 1123.2 14-Jul-19 13:46:00 1132.7 04-Aug-19 13:57:00 966.11 03-Sep-19 12:45:00 1053.8 02-Oct-19 13:54:00 946.32 08-Nov-19 11:50:00 777 13-Dec-19 12:18:00 738.4
MinutelyMin = retime(TT1, 'minutely', 'min');
MonthlyMin = retime(TT1, 'monthly', 'min');
MonthDayMin = MonthlyToMinutely(MonthlyMin,MinutelyMin)
MonthDayMin = 12×2 table
date_time Wind __________________ _______ 11-Jan-19 22:59:00 -15.904 23-Feb-19 22:45:00 -13.189 27-Mar-19 23:36:00 -12.413 23-Apr-19 19:17:00 -18.232 04-May-19 21:30:00 -18.813 29-Jun-19 01:59:00 -16.68 10-Jul-19 21:13:00 -18.426 29-Aug-19 04:04:00 -7.952 14-Sep-19 06:08:00 -9.697 06-Oct-19 00:50:00 -19.589 17-Nov-19 21:04:00 -17.65 26-Dec-19 17:52:00 -18.62
function ExactTime = MonthlyToMinutely(MonthlyTT,MinutelyTT)
MinutelyVN = MinutelyTT.Properties.VariableNames;
MonthlyVN = MonthlyTT.Properties.VariableNames;
if ~strcmp(MinutelyVN{:}, MonthlyVN{:})
ExactTime = timetable();
fprintf('Variable names %s and %s in the argument timetables are not the same.',MonthlyVN{:},MinutelyVN{:})
return
end
[yhn,mhn,dhn] = ymd(MinutelyTT.date_time); % Year, Month, Day Of Daily Maxima
for k = 1:numel(MonthlyTT)
[ym,mm,dm] = ymd(MonthlyTT.date_time(k)); % Year, Month, Day Of Monthily Maxima
Lv = ismember([yhn,mhn], [ym,mm], 'rows');
idx = MinutelyTT{:,1}(Lv) == MonthlyTT{:,1}(k);
Mv = find(Lv);
Dv = find(idx);
HM = MinutelyTT(Mv(Dv(1)),:);
MonthDayTT(k,:) = timetable2table(HM);
end
ExactTime = MonthDayTT;
end
I have no idea what the units are here, however it seems to work when I run it.
There may not be unique values in each daily data set for the maxima and minima. My code defaults to whatever retime does in those situations. In my ‘MonthlyToMinutely’ function, the ‘idx’ vector is a logical vector, and could return multiple results. I solve that problem by returning the first result (the ‘HM’ assignment in the loop) rather than all of them, because returning all of them would disrupt the table result. It allows for only one result per row. Returning all of them causes problems with the table format.
.
It seems to me that would simply be this —
LD = load(websave('T','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1289405/T.mat'));
TT1 = LD.T
TT1 = 513077×1 timetable
date_time Wind __________________ ______ 01-Jan-19 00:00:00 -5.624 01-Jan-19 00:03:00 -5.624 01-Jan-19 00:04:00 -5.818 01-Jan-19 00:05:00 -5.818 01-Jan-19 00:06:00 -6.012 01-Jan-19 00:07:00 -6.206 01-Jan-19 00:08:00 -6.788 01-Jan-19 00:09:00 -5.818 01-Jan-19 00:10:00 -5.43 01-Jan-19 00:11:00 -5.818 01-Jan-19 00:12:00 -6.012 01-Jan-19 00:13:00 -5.43 01-Jan-19 00:14:00 -6.012 01-Jan-19 00:15:00 -5.236 01-Jan-19 00:16:00 -5.818 01-Jan-19 00:17:00 -6.206
% return
% LD = load(websave('dataset','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1255052/dataset.mat'));
% TT1 = LD.TT1
MinutelyMax = retime(TT1, 'minutely', 'max');
DailyMax = retime(TT1, 'daily', 'max');
DayMinuteMax = MonthlyToMinutely(DailyMax,MinutelyMax);
DayMinuteMax
DayMinuteMax = 365×2 table
date_time Wind __________________ ______ 01-Jan-19 12:48:00 549.1 02-Jan-19 10:56:00 495.95 03-Jan-19 15:36:00 284.34 04-Jan-19 13:11:00 667.41 05-Jan-19 12:43:00 504.87 06-Jan-19 14:11:00 534.16 07-Jan-19 12:42:00 675.17 01-Jan-19 12:52:00 542.11 05-Jan-19 09:19:00 103.96 10-Jan-19 12:26:00 702.32 01-Jan-19 12:47:00 548.9 01-Jan-19 11:00:00 350.87 13-Jan-19 12:27:00 543.28 06-Jan-19 10:59:00 417.79 15-Jan-19 12:46:00 537.46 15-Jan-19 13:21:00 529.51
MinutelyMin = retime(TT1, 'minutely', 'min');
DailyMin = retime(TT1, 'daily', 'min');
DayMinuteMin = MonthlyToMinutely(DailyMin,MinutelyMin);
DayMinuteMin
DayMinuteMin = 365×2 table
date_time Wind __________________ _______ 01-Jan-19 22:10:00 -11.637 02-Jan-19 07:24:00 -12.413 01-Jan-19 18:53:00 -10.667 04-Jan-19 01:28:00 -12.801 05-Jan-19 22:35:00 -12.995 04-Jan-19 01:28:00 -12.801 07-Jan-19 02:06:00 -13.383 08-Jan-19 05:34:00 -14.74 02-Jan-19 00:36:00 -11.831 01-Jan-19 21:49:00 -10.861 11-Jan-19 22:59:00 -15.904 01-Jan-19 22:53:00 -11.443 04-Jan-19 01:28:00 -12.801 02-Jan-19 01:22:00 -12.219 02-Jan-19 00:36:00 -11.831 08-Jan-19 06:14:00 -13.577
% G = findgroups(day(AllMin.date_time),month(AllMin.date_time),hour(AllMin.date_time),minute(AllMin.date_time),AllMin{:,1});
% MinutelyMax = retime(TT1, 'minutely', 'max');
% DailyMax = retime(TT1, 'daily', 'max');
% DayMinujteMax = MonthlyToMinutely(DailyMax,MinutelyMax)
%
% MinutelyMin = retime(TT1, 'minutely', 'min');
% DailyMin = retime(TT1, 'daily', 'min');
% DayMinuteMin = MonthlyToMinutely(DailyMin,MinutelyMin)
function [ExactTime,AllMatches] = MonthlyToMinutely(MonthlyTT,MinutelyTT)
MinutelyVN = MinutelyTT.Properties.VariableNames;
MonthlyVN = MonthlyTT.Properties.VariableNames;
if ~strcmp(MinutelyVN{:}, MonthlyVN{:})
ExactTime = timetable();
fprintf('Variable names %s and %s in the argument timetables are not the same.',MonthlyVN{:},MinutelyVN{:})
return
end
[yhn,mhn,dhn] = ymd(MinutelyTT.date_time); % Year, Month, Day Of Daily Maxima
for k = 1:numel(MonthlyTT)
[ym,mm,dm] = ymd(MonthlyTT.date_time(k)); % Year, Month, Day Of Monthily Maxima
Lv = ismember([yhn,mhn], [ym,mm], 'rows');
idx = MinutelyTT{:,1}(Lv) == MonthlyTT{:,1}(k);
Mv = find(Lv);
Dv = find(idx);
HM = MinutelyTT(Mv(Dv(1)),:);
MonthDayTT(k,:) = timetable2table(HM);
end
ExactTime = MonthDayTT;
end
As I mentioned, my ‘MonthlyToMinutely’ function returns the first instance of the match that it finds, if there are more than one. This preserves the integrity of the ‘ExactTime’ output table.
I changed it to return multiple times for the same values as the second output, if the variable values are not unique. That works for the minimum values, however it’s returning anomalous results for the maximum values. I’ll work on it offlline and include it when I understand what the problem is.
EDIT — Forgot to run the code before I submitted it.
.
Only one max value per day appears in the ‘ExactTime’ result, although there can be more than one detected. My ‘MonthlyToMinutely’ function returns the first one it finds.
The problem was the resolution in the two arrays. For the time being, I’m using two different functions. I’ll work on the function to add an option (extra arguments) to make it more flexible. It will likely take some time to get that working properly. In the interim, the differences are explained by the code in the different functions, specifically in the ‘Lv’ and ‘idx’ assignments.
Try this —
LD = load(websave('T','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1289405/T.mat'));
TT1 = LD.T
TT1 = 513077×1 timetable
date_time Wind __________________ ______ 01-Jan-19 00:00:00 -5.624 01-Jan-19 00:03:00 -5.624 01-Jan-19 00:04:00 -5.818 01-Jan-19 00:05:00 -5.818 01-Jan-19 00:06:00 -6.012 01-Jan-19 00:07:00 -6.206 01-Jan-19 00:08:00 -6.788 01-Jan-19 00:09:00 -5.818 01-Jan-19 00:10:00 -5.43 01-Jan-19 00:11:00 -5.818 01-Jan-19 00:12:00 -6.012 01-Jan-19 00:13:00 -5.43 01-Jan-19 00:14:00 -6.012 01-Jan-19 00:15:00 -5.236 01-Jan-19 00:16:00 -5.818 01-Jan-19 00:17:00 -6.206
MinutelyMax = retime(TT1, 'minutely', 'max');
DailyMax = retime(TT1, 'daily', 'max');
[DayMinuteMax,AllMax] = DailyToMinutely(DailyMax,MinutelyMax);
DayMinuteMax
DayMinuteMax = 365×2 table
date_time Wind __________________ ______ 01-Jan-19 12:48:00 549.1 02-Jan-19 10:56:00 495.95 03-Jan-19 15:36:00 284.34 04-Jan-19 13:11:00 667.41 05-Jan-19 12:43:00 504.87 06-Jan-19 14:11:00 534.16 07-Jan-19 12:42:00 675.17 08-Jan-19 12:42:00 542.11 09-Jan-19 14:14:00 103.96 10-Jan-19 12:26:00 702.32 11-Jan-19 12:29:00 548.9 12-Jan-19 13:48:00 350.87 13-Jan-19 12:27:00 543.28 14-Jan-19 11:07:00 417.79 15-Jan-19 12:46:00 537.46 16-Jan-19 13:00:00 529.51
AllMax = cat(1,AllMax{:})
AllMax = 397×1 timetable
date_time Wind __________________ ______ 01-Jan-19 12:48:00 549.1 02-Jan-19 10:56:00 495.95 03-Jan-19 15:36:00 284.34 04-Jan-19 13:11:00 667.41 05-Jan-19 12:43:00 504.87 06-Jan-19 14:11:00 534.16 07-Jan-19 12:42:00 675.17 08-Jan-19 12:42:00 542.11 09-Jan-19 14:14:00 103.96 10-Jan-19 12:26:00 702.32 11-Jan-19 12:29:00 548.9 11-Jan-19 12:30:00 548.9 12-Jan-19 13:48:00 350.87 13-Jan-19 12:27:00 543.28 14-Jan-19 11:07:00 417.79 15-Jan-19 12:46:00 537.46
MinutelyMin = retime(TT1, 'minutely', 'min');
DailyMin = retime(TT1, 'daily', 'min');
[DayMinuteMin,AllMin] = DailyToMinutely(DailyMin,MinutelyMin);
DayMinuteMin
DayMinuteMin = 365×2 table
date_time Wind __________________ _______ 01-Jan-19 22:10:00 -11.637 02-Jan-19 07:24:00 -12.413 03-Jan-19 23:47:00 -10.667 04-Jan-19 01:28:00 -12.801 05-Jan-19 22:35:00 -12.995 06-Jan-19 00:03:00 -12.801 07-Jan-19 02:06:00 -13.383 08-Jan-19 05:34:00 -14.74 09-Jan-19 03:50:00 -11.831 10-Jan-19 17:52:00 -10.861 11-Jan-19 22:59:00 -15.904 12-Jan-19 22:23:00 -11.443 13-Jan-19 04:33:00 -12.801 14-Jan-19 02:24:00 -12.219 15-Jan-19 23:30:00 -11.831 16-Jan-19 06:17:00 -13.577
AllMin = cat(1,AllMin{:})
AllMin = 570×1 timetable
date_time Wind __________________ _______ 01-Jan-19 22:10:00 -11.637 01-Jan-19 22:11:00 -11.637 02-Jan-19 07:24:00 -12.413 03-Jan-19 23:47:00 -10.667 04-Jan-19 01:28:00 -12.801 05-Jan-19 22:35:00 -12.995 05-Jan-19 23:20:00 -12.995 06-Jan-19 00:03:00 -12.801 06-Jan-19 20:50:00 -12.801 06-Jan-19 20:56:00 -12.801 06-Jan-19 23:02:00 -12.801 07-Jan-19 02:06:00 -13.383 07-Jan-19 02:29:00 -13.383 08-Jan-19 05:34:00 -14.74 09-Jan-19 03:50:00 -11.831 09-Jan-19 03:51:00 -11.831
function [ExactTime,AllMatches] = DailyToMinutely(MonthlyTT,MinutelyTT)
MinutelyVN = MinutelyTT.Properties.VariableNames;
MonthlyVN = MonthlyTT.Properties.VariableNames;
if ~strcmp(MinutelyVN{:}, MonthlyVN{:})
ExactTime = timetable();
fprintf('Variable names %s and %s in the argument timetables are not the same.',MonthlyVN{:},MinutelyVN{:})
return
end
[yhn,mhn,dhn] = ymd(MinutelyTT.date_time); % Year, Month, Day Of Daily Maxima
for k = 1:numel(MonthlyTT)
[ym,mm,dm] = ymd(MonthlyTT.date_time(k)); % Year, Month, Day Of Monthily Maxima
% YrMoDa = [ym mm dm]
Lv = ismember([yhn,mhn,dhn], [ym,mm,dm], 'rows');
idx = MinutelyTT{:,1}(Lv) == MonthlyTT{:,1}(k);
% LvSize = nnz(Lv)
Mv = find(Lv);
Dv = find(idx);
HM = MinutelyTT(Mv(Dv(1)),:);
AllHM{k,:} = MinutelyTT(Mv(Dv),:);
MonthDayTT(k,:) = timetable2table(HM);
end
ExactTime = MonthDayTT;
AllMatches = AllHM;
end
.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!