Convert Time (string) to Time (numeric)

143 次查看(过去 30 天)
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.

回答(1 个)

Star Strider
Star Strider 2019-6-7
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.

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by