Main Content

hours

Duration in hours

Description

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'.

example

Examples

collapse all

X = magic(4);
H = hours(X)
H = 4x4 duration
   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
    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

Version History

Introduced in R2014b