Azzera filtri
Azzera filtri

Convert Time (string) to Time (numeric)

143 visualizzazioni (ultimi 30 giorni)
Patrick Rungrugeecharoen
Patrick Rungrugeecharoen il 7 Giu 2019
Risposto: Star Strider il 7 Giu 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.

Risposte (1)

Star Strider
Star Strider il 7 Giu 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.

Categorie

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

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by