Effacer les filtres
Effacer les filtres

Convert Time (string) to Time (numeric)

143 vues (au cours des 30 derniers jours)
Patrick Rungrugeecharoen
Patrick Rungrugeecharoen le 7 Juin 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.

Réponses (1)

Star Strider
Star Strider le 7 Juin 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.

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by