How can i Replace missing values from Timetable

25 ビュー (過去 30 日間)
Ioannis Tsikriteas
Ioannis Tsikriteas 2018 年 6 月 9 日
Hi, i have a Timetable TT1 with a bunch of NaN values on his Data and a second TT2 with the correct values (replacements of NaN's).
How can i replace the Nan value with the correct one at each timestamp?

採用された回答

Paolo
Paolo 2018 年 6 月 9 日
Input timetables:
tt1:
Time Var1
___________ ____
13-Apr-2018 30.1
25-Apr-2018 NaN
26-Apr-2018 12
28-Apr-2018 NaN
tt2:
Time Var1
___________ ____
13-Apr-2018 37.3
25-Apr-2018 41
26-Apr-2018 42.3
28-Apr-2018 55
%Create timetables.
tt1 = timetable(datetime({'13/04/2018';'25/04/2018';'26/04/2018';'28/04/2018'}),[30.1;NaN;12;NaN]);
tt2 = timetable(datetime({'13/04/2018';'25/04/2018';'26/04/2018';'28/04/2018'}), [37.3;41;42.3;55]);
%Find NaN indexes in first timetable.
x = isnan(tt1.Var1);
%Use indexes to replace values in tt1.Var1 with tt2.Var1.
tt1.Var1(x) = tt2.Var1(x);
Output:
Time Var1
___________ ____
13-Apr-2018 30.1
25-Apr-2018 41
26-Apr-2018 12
28-Apr-2018 55
  1 件のコメント
Ioannis Tsikriteas
Ioannis Tsikriteas 2018 年 6 月 9 日
Yes that definitely solved my problem! Thanks a lot, i had the logical index of the nan values and the last command was what it was misiing

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by