Need to convert string and character to time in Matlab
6 views (last 30 days)
Show older comments
Cassondra Fileccia
on 30 Apr 2021
Commented: Cassondra Fileccia
on 30 Apr 2021
I have a string that reads "12-38-09" and a 1x6 char that is 123804. I need both of these to be displayed as a HH:MM:SS format of time. How can I do that? Also, I am not including dates, just times.
0 Comments
Accepted Answer
Walter Roberson
on 30 Apr 2021
Unfortunately, the 'inputformat' option for duration() is much less flexible than for datetime()
duration(sscanf('12-38-09', '%2d-%2d-%2d').')
duration(sscanf('123809', '%2d%2d%2d').')
If you have a bunch of these, you might alter the code a bit depending on how they are stored.
3 Comments
Walter Roberson
on 30 Apr 2021
duration(sscanf(eyeTrackingTime, '%2d-%2d-%2d').')
duration(sscanf(eyeTrackingTime, '%2d%2d%2d').')
If you do not know ahead of time whether the variable will have the dashes or not, then we could deal with that too.
duration(str2double(regexp(eyeTrackingTime,'\d\d', 'match')))
You might need .' after the )) before the third )
More Answers (0)
See Also
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!