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'.
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!