Need to convert string and character to time in Matlab

6 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2021-4-30
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 个评论
Walter Roberson
Walter Roberson 2021-4-30
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 )

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by