Need to convert string and character to time in Matlab

6 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de Abr. de 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 comentarios
Walter Roberson
Walter Roberson el 30 de Abr. de 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 )
Cassondra Fileccia
Cassondra Fileccia el 30 de Abr. de 2021
Thank you so much that worked!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by