# hour to hour minute second conversion

10 visualizzazioni (ultimi 30 giorni)
sermet il 30 Ago 2016
Modificato: Teja Muppirala il 30 Ago 2016
I have an array represents hours, for example;
hour=[13.20,15.30,14.46,21];
Is there any matlab function to convert these hours to hour, minute, second? Example output;
hms=[13 12 0;15 18 0;14 27 36;21 0 0];
##### 0 CommentiMostra -1 commenti meno recentiNascondi -1 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Stephen23 il 30 Ago 2016
Modificato: Stephen23 il 30 Ago 2016
The basic concept is easy to implement:
tmp = hour(:);
H = fix(tmp);
tmp = 60*(tmp-H);
M = fix(tmp);
tmp = 60*(tmp-M);
S = tmp;
hms = [H,M,S]
However this can lead to accumulated floating point errors. One way to resolve this would be to perform some intermediate rounding like this:
H = fix(tmp);
M = fix(tmp);
S = tmp;
hms = [H,M,S]
to give
hms =
13 12 0
15 18 0
14 27 36
21 0 0
##### 0 CommentiMostra -1 commenti meno recentiNascondi -1 commenti meno recenti

Accedi per commentare.

### Più risposte (1)

Teja Muppirala il 30 Ago 2016
Modificato: Teja Muppirala il 30 Ago 2016
myTimes=[13.20,15.30,14.46,21];
HR = hours(myTimes');
[H,M,S] = hms(HR);
HMS = [H M S]
This gives
HMS =
13 12 0
15 18 0
14 27 36
21 0 0
##### 0 CommentiMostra -1 commenti meno recentiNascondi -1 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by