How to read time from a .txt file ?

9 views (last 30 days)
I have got a column of time in the format "hh:mm:ss.SSS". How do i read this entire column in Matlab and convert it into decimal ?
  1 Comment
madhan ravi
madhan ravi on 5 Mar 2019
Use readtable() to read the file.
The problem is Matlab is only reading hh:mm:ss . I have my data in milliseconds like this 00:00:01.456 . How do i potentially convert this to decimal system?
With the example you gave it worked fine for me. Perhaps show the code that you are trying to read the file and if possible upload the file.

Sign in to comment.

Answers (1)

Prajwal Kadlaplamutt Ravindra Kumar
So basically i am importing the data from the .txt file and reading the first column and fifth column. I am then using diff function to calculate dx/dt. The problem is with time. Since its not considering the milliseconds part i am getting 0 as the answer when i use diff function for time.
  1 Comment
Peter Perkins
Peter Perkins on 11 Mar 2019
Prajwal, this may just be a display issue. Try this:
t.Time.Format = "hh:mm:ss.SSS"
(Substitute the correct names of your table and the time variable.) If that's not it, you should confirm that you are reading them in as durations (which has only been suppoted since R2018a IIRC).
Your code uses load. I'm not even sure what that would do on your file. Use readtable.

Sign in to comment.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!