Readtable reads my timestamp data as NaN
19 views (last 30 days)
I am in a bit of a pickle, as I am trying to use readtable() to read my csv file. However, all of the data in the timestamp columns is being read in as NaNs. There are only a few exceptions where it reads it correctly. I am confused, as the formatting looks correct.
I have used, readtable(), readmatrix(), and dlmread(). I have also tried saving it as a .xlsx file, which allows me to read the file correctly. However, I have a myriad of .csv files that follow the same format, and it would be a huge pain to convert them all to .xslx.
The csv file format (copy and pasted directly from the file) goes like this:
Heart Monitor,Heart_Mon TmStamp,Accel_X,Accel_Y,Accel_Z,Accel_TmStamp,Respiratory, Resp TmStamp
Any help would pbe greatly appreciated!
Walter Roberson on 7 Aug 2020
filename = 'heart.csv';
S = fileread(filename);
datacell = textscan(regexprep(S, ':(\d\d\d)', '.$1'), '%f%T%f%f%f%T%f%T', 'headerlines', 1, 'delimiter', ',');
You can cell2table(datacell), providing 'VariableNames' .