Borrar filtros
Borrar filtros

Convert Time (string) to Time (numeric)

143 visualizaciones (últimos 30 días)
Patrick Rungrugeecharoen
Patrick Rungrugeecharoen el 7 de Jun. de 2019
Respondida: Star Strider el 7 de Jun. de 2019
Right now I have a vector string which is a 130611 x 1 string.
This string contains values such as:
The first row is 0 hrs 5 mins 0 secs, second row is 0 hrs 5 mins 0 secs, third row is 0 hrs 13 mins 0 secs etc.
I would like to return the same sized vector but telling me only minutes?
For instance "01:10:00" would return 70.

Respuestas (1)

Star Strider
Star Strider el 7 de Jun. de 2019
You can use the datetime data type (with a few alterations, since duration for some reason does not accept datetime objects as arguments, or at least does not when I try it):
dtv = datevec(datetime({'00:05:00';'01:10:00';'23:59:59'},'InputFormat','HH:mm:ss'));
da = duration(dtv(:,4:end));
mins = minutes(da)
producing:
da =
00:05:00
01:10:00
23:59:59
mins =
5
70
1440
I posted ‘da’ to demonstrate the conversion. It is not necessary to return it specifically.
The duration data does not ‘wrap’ unless you also supply the year-month-day values, so as long as your data are all in the same 24-hour day, they will be accurate.

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by