필터 지우기
필터 지우기

Convert Time(string) to Time(number)

조회 수: 14 (최근 30일)
Patrick Rungrugeecharoen
Patrick Rungrugeecharoen 2019년 6월 7일
댓글: dpb 2019년 6월 8일
Right now I have this vector that is a 130611 x 1 string (see below)
Row 1 reads: 0 hrs 5 mins 0 secs.
Row 2 reads: 0 hrs 5 mins 0 secs.
Row 3 reads: 0 hrs 13 mins 0 secs.
I would like to know how to get this to convert to a number vector of the same size but in minutes?
For instance "01:10:00" would be converted to 70.

답변 (1개)

dpb
dpb 2019년 6월 7일
편집: dpb 2019년 6월 7일
A little bit circuitous as for some reason TMW doesn't let one create a duration array from scanning text...why is beyond my ken... :(
Example sequence for given text...obviously can read the file to get the text input as startting point:
t=datetime('01:10:00'); % first get to datetime class--will have current day embedded as can't have just time
d=duration(hour(t),minute(t),second(t),'format','m'); % convert that datetime array to a duration array
m=minutes(d); % if want just double array of minutes as numeric
The duration array d will disply as '70 min' and will be of class duration. One can do time-related calculations and/or plot etc., with it in that form. It wouldn't work for regression or other numerical operations if that is end need.
The m vector is the numerical value of the minutes as just straight, ordinary double array if that is what is needed.
  댓글 수: 4
Steven Lord
Steven Lord 2019년 6월 8일
As a bit of an aside, dpb, are you using one of the license types that comes with access to MATLAB Online? If so you could use that to use the latest release, no installation required.
dpb
dpb 2019년 6월 8일
Hmmm...wasn't aware of that being an option, Steven, thanks. I'm not sure; I'll have to check...altho our rural bandwidth isn't the greatest (but at least do now finally! have a signal that wasn't the case until about 4-5 yr ago).

댓글을 달려면 로그인하십시오.

카테고리

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