Need to convert string and character to time in Matlab

3 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Walter Roberson
Walter Roberson il 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 Commenti
Walter Roberson
Walter Roberson il 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 )

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by