datetime - Error in converting date-time to number in MATLAB -
i have .csv file contains 2 columns of time data. want convert date number, following error:
??? error using ==> datenum @ 174 datenum failed. error in ==> interpolasi_suhu_dan_waktu_16_02_17 @ 21 t = datenum(m{1}); caused by: error using ==> dtstr2dtvecmx input cell array must either column or row.
here .csv file (waktu_16_02_17.csv):
0:03:13 0:02:58 0:13:13 0:12:58 0:23:13 0:22:58 0:33:13 0:32:56 0:43:13 0:42:58 0:48:11 0:57:59 0:58:13 1:07:59 1:08:13 1:17:59 1:18:13 1:27:59 1:28:14 1:37:57 1:38:14 1:52:59 1:44:31 2:02:57
and code used is:
fid = fopen('waktu_16_02_17.csv', 'r'); m = textscan(fid, '%s %s', 'delimiter', ',', 'collectoutput', 1); fclose(fid); format short g g = m{1};
can me figure out what's going wrong?
still can't see correct formatting of csv file (is \n
after each string? 2 strings or 1 long?). code works me.
i copied data , create new .csv file. contains 1 string. after using code (using whos
command):
name size bytes class attributes m 1x1 718 cell
next, lets see inside of m
:
m{1} ans = 1×2 cell array '0:03:13 0:02:58 0:13:13 0:12:58 0:23:13 0:22:58 0:33:13 0:32:56 0:43:…' ''
we can see m
has 2 cells. first 1 contains string data csv , second 1 empty. ok, lets put in g
string csv:
g = m{1}{1}
in code used g = m{1}
take data need 1 level deeper. maybe can use m{1}
if csv has formatting , textscan return resulting string in m
. ok, g
char array contains 191 char symbols: dates , spaces.
now problem - incorrect data type datenum
function. can use datenum
cell arrays, cell array must string of column. looks m{1}
array table (2 strings , columns).
in case use datenum
g
char array have go way:
datenum(g(1:8)) ans = 7.367e+05
this way how correct datenum
first date data. of them split array correct parts (use loops or arrayfun
functions etc.).
hope helps!
Comments
Post a Comment