Effacer les filtres
Effacer les filtres

How to extrapolate data with NaN data series?

5 vues (au cours des 30 derniers jours)
Tyann Hardyn
Tyann Hardyn le 30 Oct 2021
Réponse apportée : Chunru le 30 Oct 2021
Hi, everyone
I want to ask about how to extrapolate a data series with NaN in the data. So i have a data series like this :
magnetH = [21340; 21340; 21340; 21341; 21341; NaN; NaN; 21340; NaN; NaN]
time_series = [1978-03-29 00:00:00; 1978-03-29 00:01:00; 1978-03-29 00:02:00; 1978-03-29 00:03:00
1978-03-29 00:04:00; 1978-03-29 00:05:00; 1978-03-29 00:06:00; 1978-03-29 00:07:00
1978-03-29 00:08:00; 1978-03-29 00:09:00]
extrapolat_time = [1978-03-29 00:00:00; 1978-03-29 00:01:00; 1978-03-29 00:02:00; 1978-03-29 00:03:00
1978-03-29 00:04:00; 1978-03-29 00:05:00; 1978-03-29 00:06:00; 1978-03-29 00:07:00
1978-03-29 00:08:00; 1978-03-29 00:09:00; 1978-03-29 00:10:00; 1978-03-29 00:11:00
1978-03-29 00:12:00; 1978-03-29 00:13:00; 1978-03-29 00:14:00; 1978-03-29 00:15:00
1978-03-29 00:16:00; 1978-03-29 00:17:00; 1978-03-29 00:18:00; 1978-03-29 00:19:00]
The time series data is a combination between datetime and duration data (yyyy-MM-dd hh:mm:ss) with 1 minute of space between each data. Now, i want to extrapolate the data of magnetH to be defined at extrapolat_time data series....
Would it be possible anyone? Thanks for your help and cooperation.... Iam very grateful, if someone can solve my problem...
/.\ /.\ /.\

Réponse acceptée

Chunru
Chunru le 30 Oct 2021
magnetH = [21340; 21340; 21340; 21341; 21341; NaN; NaN; 21340; NaN; NaN];
% The original time_series statement are invalid
time_series = ["1978-03-29 00:00:00"; "1978-03-29 00:01:00"; "1978-03-29 00:02:00"; "1978-03-29 00:03:00"; ...
"1978-03-29 00:04:00"; "1978-03-29 00:05:00"; "1978-03-29 00:06:00"; "1978-03-29 00:07:00"; ...
"1978-03-29 00:08:00"; "1978-03-29 00:09:00"];
t = datetime(time_series, "Format", "yyyy-MM-dd HH:mm:ss")
t = 10×1 datetime array
1978-03-29 00:00:00 1978-03-29 00:01:00 1978-03-29 00:02:00 1978-03-29 00:03:00 1978-03-29 00:04:00 1978-03-29 00:05:00 1978-03-29 00:06:00 1978-03-29 00:07:00 1978-03-29 00:08:00 1978-03-29 00:09:00
% extrapolat_time = [1978-03-29 00:00:00; 1978-03-29 00:01:00; 1978-03-29 00:02:00; 1978-03-29 00:03:00
% 1978-03-29 00:04:00; 1978-03-29 00:05:00; 1978-03-29 00:06:00; 1978-03-29 00:07:00
% 1978-03-29 00:08:00; 1978-03-29 00:09:00; 1978-03-29 00:10:00; 1978-03-29 00:11:00
% 1978-03-29 00:12:00; 1978-03-29 00:13:00; 1978-03-29 00:14:00; 1978-03-29 00:15:00
% 1978-03-29 00:16:00; 1978-03-29 00:17:00; 1978-03-29 00:18:00; 1978-03-29 00:19:00]
ti = t(1) + (0:19)'/(24);
% using fillmissing to replace the nans.
magnetHi = interp1(t, fillmissing(magnetH, 'linear'), ti, 'linear', 'extrap')
magnetHi = 20×1
1.0e+04 * 2.1340 2.1322 2.1302 2.1282 2.1262 2.1242 2.1222 2.1202 2.1182 2.1162

Plus de réponses (0)

Catégories

En savoir plus sur Time Series dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by