# Convert variable to numeric in TimeTable

조회 수: 8 (최근 30일)
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 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이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Eric Escoto 2020년 9월 21일
Worked perfectly!

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Timetables에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by