How do i insert seconds in a timeseries data when the frequency of the data is inconsistent?
Afficher commentaires plus anciens
I have a timeseries data as:
And i need to insert seconds on this data in way that it depends upon the number of datapoints the minutues has. For example, 9/5/2021 11:30:00 has 5 datapoints so every data will be increased by {60/5= 12 seconds), 11:31:00 has 3 data points so, every data is increased by {60/3=20 seconds).
Input_data=
9/5/2021 11:30:00
9/5/2021 11:30:00
9/5/2021 11:30:00
9/5/2021 11:30:00
9/5/2021 11:30:00
9/5/2021 11:31:00
9/5/2021 11:31:00
9/5/2021 11:31:00
9/5/2021 11:32:00
9/5/2021 11:32:00
9/5/2021 11:32:00
9/5/2021 11:32:00
Final_output=
9/5/2021 11:30:00
9/5/2021 11:30:12
9/5/2021 11:30:24
9/5/2021 11:30:36
9/5/2021 11:30:48
9/5/2021 11:31:00
9/5/2021 11:31:20
9/5/2021 11:31:40
9/5/2021 11:32:00
9/5/2021 11:32:15
9/5/2021 11:32:30
9/5/2021 11:32:45
Réponse acceptée
Plus de réponses (1)
dpb
le 8 Juin 2021
indx=[0;find(minutes(diff(TT.Time)));height(TT)]; % find change locations indices
N=diff(indx); % number observations/group
secs=60./N; % number seconds differential in group
dsecs=arrayfun(@(s,n)s*[(0:n-1).'],secs,N,'UniformOutput',false); % compute the vector of addends
dsecs=vertcat(dsecs{:});
TT.Time=TT.Time+dsecs; % fixup the time field
Applied to your sample, this results in--
>> TT =
12×1 timetable
Time x
____________________ ____
05-Sep-2021 11:30:00 0.18
05-Sep-2021 11:30:12 0.34
05-Sep-2021 11:30:24 0.21
05-Sep-2021 11:30:36 0.51
05-Sep-2021 11:30:48 0.91
05-Sep-2021 11:31:00 0.63
05-Sep-2021 11:31:20 0.10
05-Sep-2021 11:31:40 0.39
05-Sep-2021 11:32:00 0.05
05-Sep-2021 11:32:15 0.50
05-Sep-2021 11:32:30 0.43
05-Sep-2021 11:32:45 1.00
>>
where I just created a dummy variable to have a non-empty TT.
Catégories
En savoir plus sur Time Series Collections dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!