Documentation

hours

Duration in hours

Syntax

H = hours(X)

Description

example

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

  • IfXis a numeric array, thenHis adurationarray in units of hours.

  • IfXis adurationarray, thenHis adoublearray with each element equal to the number of hours in the corresponding element ofX.

Thehoursfunction converts betweendurationanddoublevalues. To display a duration in units of hours, set itsFormatproperty to'h'.

Examples

collapse all

X = magic(4); H = hours(X)
H =4×4 duration array16 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 adurationarray.

X = hours(2:10:38) + minutes(30)
X =1×4 duration array2.5 hr 12.5 hr 22.5 hr 32.5 hr

Convert each duration inXto a number of hours.

H = hours(X)
H =2.5000 12.5000 22.5000 32.5000

View the data type ofH

whosH
类Attribu名字大小字节tes 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

Was this topic helpful?