Convert variable to numeric in TimeTable

10 vues (au cours des 30 derniers jours)
Eric Escoto
Eric Escoto le 21 Sep 2020
Commenté : Eric Escoto le 21 Sep 2020
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'.

Réponse acceptée

Adam Danz
Adam Danz le 21 Sep 2020
Modifié(e) : Adam Danz le 21 Sep 2020
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 commentaire
Eric Escoto
Eric Escoto le 21 Sep 2020
Worked perfectly!
Thanks, Adam

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Conversion 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