This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Duration in hours


H = hours(X)



H = hours(X) returns an array of hours equivalent to the values in X.

  • If X is a numeric array, then H is a duration array in units of hours.

  • If X is a duration array, then H is a double array with each element equal to the number of hours in the corresponding element of X.

The hours function converts between duration and double values. To display a duration in units of hours, set its Format property to 'h'.


collapse all

X = magic(4);
H = hours(X)
H = 4x4 duration array
   16 hr    2 hr    3 hr   13 hr
    5 hr   11 hr   10 hr    8 hr
    9 hr    7 hr    6 hr   12 hr
    4 hr   14 hr   15 hr    1 hr

Create a duration array.

X = hours(2:10:38) + minutes(30)
X = 1x4 duration array
    2.5 hr   12.5 hr   22.5 hr   32.5 hr

Convert each duration in X to a number of hours.

H = hours(X)
H = 1×4

    2.5000   12.5000   22.5000   32.5000

View the data type of H

whos H
  Name      Size            Bytes  Class     Attributes

  H         1x4                32  double              

Input Arguments

collapse all

Input array, specified as a numeric array, duration array, or logical array.

Extended Capabilities

Introduced in R2014b