How to find the corresponding date to each found maximum value?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Lei Hou
el 24 de Feb. de 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.
Respuestas (1)
Dongyue
el 17 de Nov. de 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
Best,
Dongyue
0 comentarios
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!