Azzera filtri
Azzera filtri

Convert Time(string) to Time(number)

14 visualizzazioni (ultimi 30 giorni)
Patrick Rungrugeecharoen
Patrick Rungrugeecharoen il 7 Giu 2019
Commentato: dpb il 8 Giu 2019
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.

Risposte (1)

dpb
dpb il 7 Giu 2019
Modificato: dpb il 7 Giu 2019
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 Commenti
Steven Lord
Steven Lord il 8 Giu 2019
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 il 8 Giu 2019
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).

Accedi per commentare.

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