Convert variable to numeric in TimeTable

10 次查看(过去 30 天)
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by