Effacer les filtres
Effacer les filtres

Convert Time(string) to Time(number)

14 vues (au cours des 30 derniers jours)
Patrick Rungrugeecharoen
Patrick Rungrugeecharoen le 7 Juin 2019
Commenté : dpb le 8 Juin 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.

Réponses (1)

dpb
dpb le 7 Juin 2019
Modifié(e) : dpb le 7 Juin 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 commentaires
Steven Lord
Steven Lord le 8 Juin 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 le 8 Juin 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).

Connectez-vous pour commenter.

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