How do I convert a cell array of character strings into datetime array efficiently?
Show older comments
I have a cell array of character strings which contains column headers and my time stamp information we will call txt. I want to be able to efficiently extract the timestamp column and convert it to seconds. counting up from zero at the first entry. I tried to use datenum as follows;
t=(datenum(txt{6:end,1})-datenum{6,1})*60^2*24
However, datenum returns a error claiming too many arguments. Next I tried to use cellfun to do the job;
t=(cellfun(@datenum,txt{6:end,1})-datenum(txt{6,1}))*60^2*24
However, this returns an error on cellfun saying input #2 was expected to be a cell array but was char instead. Surely there is a more elegant way than setting up a loop to march through and do it line by line...
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!