How to find the corresponding date to each found maximum value?

1 Ansicht (letzte 30 Tage)
SaaraL
SaaraL am 22 Feb. 2021
Beantwortet: Dongyue am 17 Nov. 2022
I have a timetable 79880x42 with precipitation data:
Date Station 1 Station 2 Station 3 ...
'01-Jan-2011 00:00:00' 0 0 0
'01-Jan-2011 01:00:00' 0.3 0 0
'01-Jan-2011 02:00:00' 0.4 0 0.6
'01-Jan-2011 03:00:00' 1.2 0 0.8
I found the maximum value TTmax = retime(tt,'yearly','max'), tt=timetable, but this only gives the matrix with max values
How do I get the yearly maximum values of each station WITH the corresponding date and time?
  2 Kommentare
Lei Hou
Lei Hou am 24 Feb. 2021
Hi SaaraL,
I need more information about how you want to get. I tried the following.
>> tt = timetable((1:79880)',0.1*(1:79880)',0.01*(1:79880)','StartTime',datetime(2011,1,1,0,0,0),'TimeStep',hours(1),'VariableNames',{'Station 1' 'Station 2' 'Station 3'});
>> TTmax = retime(tt,'yearly','max')
TTmax =
10×3 timetable
Time Station 1 Station 2 Station 3
___________ _________ _________ _________
01-Jan-2011 8760 876 87.6
01-Jan-2012 17544 1754.4 175.44
01-Jan-2013 26304 2630.4 263.04
01-Jan-2014 35064 3506.4 350.64
01-Jan-2015 43824 4382.4 438.24
01-Jan-2016 52608 5260.8 526.08
01-Jan-2017 61368 6136.8 613.68
01-Jan-2018 70128 7012.8 701.28
01-Jan-2019 78888 7888.8 788.88
01-Jan-2020 79880 7988 798.8
Regarding the above result, for example 8760, it is the maximum value of "Station 1" for year 2011. It seems what you want. If not, please tell me more about your input timetable and what you want to get.
SaaraL
SaaraL am 26 Feb. 2021
The maximum values for each station are at different times, so I need to get the maximum for each station for each year and at what time was the maximum registered. Is that possible? It should look like:
Registered time Station 1 max (mm) Registered time Station 2 max (mm)
2011 07.07.2011 13:00 46 18.06.2011 11:00 36
And so forth

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Dongyue
Dongyue am 17 Nov. 2022
Hi SaaraL,
Please try the following code, and hope this will help:
clear; clc;
tt = timetable((1:79880)',0.1*(1:79880)',0.01*(1:79880)','StartTime',datetime(2011,1,1,0,0,0),'TimeStep',hours(1),'VariableNames',{'Station 1' 'Station 2' 'Station 3'});
TTmax = retime(tt,'yearly','max');
nrow = size(TTmax,1);
ncol = size(TTmax,2);
for row = 1:nrow
tmp = TTmax(row,:);
yr = year(tmp.Time);
fprintf('Year:%d | ',yr)
for col = 1:ncol
station = TTmax.Properties.VariableNames{col};
mx = tmp.(station);
tmx = tt.Time(tt.(station)==mx & year(tt.Time)==yr);
fprintf("%s: %s | %d || ",station,tmx, mx)
end
fprintf('\n')
end
Year:2011 |
Station 1 : 31-Dec-2011 23:00:00 | 8760 || Station 2 : 31-Dec-2011 23:00:00 | 876 || Station 3 : 31-Dec-2011 23:00:00 | 8.760000e+01 ||
Year:2012 |
Station 1 : 31-Dec-2012 23:00:00 | 17544 || Station 2 : 31-Dec-2012 23:00:00 | 1.754400e+03 || Station 3 : 31-Dec-2012 23:00:00 | 1.754400e+02 ||
Year:2013 |
Station 1 : 31-Dec-2013 23:00:00 | 26304 || Station 2 : 31-Dec-2013 23:00:00 | 2.630400e+03 || Station 3 : 31-Dec-2013 23:00:00 | 2.630400e+02 ||
Year:2014 |
Station 1 : 31-Dec-2014 23:00:00 | 35064 || Station 2 : 31-Dec-2014 23:00:00 | 3.506400e+03 || Station 3 : 31-Dec-2014 23:00:00 | 3.506400e+02 ||
Year:2015 |
Station 1 : 31-Dec-2015 23:00:00 | 43824 || Station 2 : 31-Dec-2015 23:00:00 | 4.382400e+03 || Station 3 : 31-Dec-2015 23:00:00 | 4.382400e+02 ||
Year:2016 |
Station 1 : 31-Dec-2016 23:00:00 | 52608 || Station 2 : 31-Dec-2016 23:00:00 | 5.260800e+03 || Station 3 : 31-Dec-2016 23:00:00 | 5.260800e+02 ||
Year:2017 |
Station 1 : 31-Dec-2017 23:00:00 | 61368 || Station 2 : 31-Dec-2017 23:00:00 | 6.136800e+03 || Station 3 : 31-Dec-2017 23:00:00 | 6.136800e+02 ||
Year:2018 |
Station 1 : 31-Dec-2018 23:00:00 | 70128 || Station 2 : 31-Dec-2018 23:00:00 | 7.012800e+03 || Station 3 : 31-Dec-2018 23:00:00 | 7.012800e+02 ||
Year:2019 |
Station 1 : 31-Dec-2019 23:00:00 | 78888 || Station 2 : 31-Dec-2019 23:00:00 | 7.888800e+03 || Station 3 : 31-Dec-2019 23:00:00 | 7.888800e+02 ||
Year:2020 |
Station 1 : 11-Feb-2020 07:00:00 | 79880 || Station 2 : 11-Feb-2020 07:00:00 | 7988 || Station 3 : 11-Feb-2020 07:00:00 | 7.988000e+02 ||
Best,
Dongyue

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by