Convert variable to numeric in TimeTable

9 ビュー (過去 30 日間)
Eric Escoto
Eric Escoto 2020 年 9 月 21 日
コメント済み: Eric Escoto 2020 年 9 月 21 日
I have a timetable with some values that are not in the correct format for further computations using 'retime'.
The portions in question seem to be designated by apostrophes surrounding the variable value.
Note the "NaN" values in Var1 of the attached file compared with 'NAN' in Var2 (ideally, 'NAN' within the timetable should be changed to NaN). Similarly in Var2, or Var6, values that should be numeric are bounded by the apostrophes (e.g. '0', '28'). Those should only be the numeric value.
Do the apostrophes mean anything and are they the problem here? Designating a differnt type of format?
How can I modify this timetable to create something I can work with?
% Compute Daily values for variables.
TT2_sta_Pin = TT1_sta(:,{'Var2'});
TT2_sta_Pisum = retime(TT2_sta_Pin, 'daily', 'sum');
Will return,
Error using timetable/retime (line 140)
All variables in input timetables must be numeric or duration when synchronizing using 'sum'.

採用された回答

Adam Danz
Adam Danz 2020 年 9 月 21 日
編集済み: Adam Danz 2020 年 9 月 21 日
Convert your columns containing cellstrings to numeric vectors.
Example:
TT1_sta.Var2 = str2double(TT1_sta.Var2);
repeat for the other cellstr columns.
If that table is produced by reading in data, instead of fixing the cellstr columns, change how you're reading in the data so that you're reading in numeric values rather than strings. Then you won't have the problem in the first place.
  1 件のコメント
Eric Escoto
Eric Escoto 2020 年 9 月 21 日
Worked perfectly!
Thanks, Adam

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTimetables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by