How can I interpret the time value in ascii to a numeric value?

I have a file that looks like this:

15:03:21 II 0.88 0.64 15:03:31 II 0.88 0.64 15:03:42 II 0.40 0.40 and others.

after loading the file in Matlab, I want to be able to read the first column (which corresponds to the time) and interpret them as numeric values. At the moment, they are interpreted as a string of ascii characters, and I can not perform any mathematical operations on them. Does anyone have any suggestions as to how I can read time as numbers instead of the ascii character string?

+3
source share
3 answers
+6

, ,

t = {'15:03:21 ' '15:03:31 ' '15:03:42 '};
datenum(t, 'HH:MM:SS')
+1

In addition to the answers above, there is another useful DATEVEC function that converts either a date string or an output-date to a year-day-hour-minute-second vector. Try:

tvec = datevec(t)

Please note that if there is only time in the line, the date will be January 1 of the current year. You can always cut it with

tvec(:,1:3) = [];
+1
source

Source: https://habr.com/ru/post/1747857/


All Articles