How can i interpret a time value in ascii into a numerical value?
I have a file which is as follows:
15:03:21 II 0.88 0.64 15:03:31 II 0.88 0.64 15:03:42 II 0.40 0.40 etc.
after loading the file in matlab, I want to be able to read the first column (which corresponds to time) and interpret them as numerical values. At the moment, they are interpreted as a string of ascii characters and i can't perform any mathematical operations on them. Does anyone have any suggestions as to how i can read the time as numbers instead of a string of开发者_高级运维 ascii characters?
Use DATENUM and DATEVEC to convert your date strings to useful numeric values.
Like Jonas said, but more specifically,
t = {'15:03:21 ' '15:03:31 ' '15:03:42 '};
datenum(t, 'HH:MM:SS')
In addition to above answers there is another useful function DATEVEC which converts either date string or datenum output to vector of year-month-day-hours-minutes-seconds. Try it out:
tvec = datevec(t)
Notice that if there is only time in the string, the date will be January 1st of the current year. You can always cut it out with
tvec(:,1:3) = [];
精彩评论