MATLAB Answers

Readtable reads my timestamp data as NaN

4 views (last 30 days)
Hello everyone!
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
370,00:40:00:799,0.86,9.59,1.45,00:40:00:803,201,00:40:00:803
367,00:40:00:805,0.99,9.46,1.04,00:40:00:808,197,00:40:00:808
365,00:40:00:811,1.25,9.57,1.81,00:40:00:814,195,00:40:00:814
365,00:40:00:816,0.96,9.44,1.03,00:40:00:820,194,00:40:00:820
Any help would pbe greatly appreciated!

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
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' .

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by