Andrea2810
Andrea2810

Reputation: 11

datenum and matrix column string conversion

I want to convert the second column of table T using datenum.

The elements of this column are '09:30:31.848', '15:35:31.325', etc. When I use datenum('09:30:31.848','HH:MM:SS.FFF') everything works, but when I want to apply datenum to the whole column it doesn't work. I tried this command datenum(T(:,2),'HH:MM:SS.FFF') and I receive this error message:

"The input to DATENUM was not an array of character vectors"

Here a snapshot of T

Thank you

Upvotes: 1

Views: 55

Answers (1)

rinkert
rinkert

Reputation: 6863

You are not calling the data from the table, but rather a slice of the table (so its stays a table). Refer to the data in the table using T.colName:

times_string = ['09:30:31.848'; '15:35:31.325'];
T = table(times_string)
times_num = datenum(T.times_string, 'HH:MM:SS.FFF')

Alternatively, you can slice the table using curly braces to extract the data (if you want to use the column number instead of name):

times_num = datenum(T{:,2}, 'HH:MM:SS.FFF')

Upvotes: 1

Related Questions