tags:

views:

31

answers:

3

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?

+5  A: 

Use DATENUM and DATEVEC to convert your date strings to useful numeric values.

Jonas
A: 

Like Jonas said, but more specifically,

t = {'15:03:21 ' '15:03:31 ' '15:03:42 '};
datenum(t, 'HH:MM:SS')
Richie Cotton
A: 

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) = [];
yuk

related questions