How to extrapolate data with NaN data series?

17 ビュー (過去 30 日間)
Tyann Hardyn
Tyann Hardyn 2021 年 10 月 30 日
回答済み: Chunru 2021 年 10 月 30 日
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...
/.\ /.\ /.\

採用された回答

Chunru
Chunru 2021 年 10 月 30 日
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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by