Convert Time(string) to Time(number)
14 ビュー (過去 30 日間)
古いコメントを表示
Right now I have this vector that is a 130611 x 1 string (see below)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/223543/image.png)
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.
0 件のコメント
回答 (1 件)
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
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
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 Center および File Exchange で Data Type Conversion についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!