Main Content

milliseconds

R2026b

Duration in milliseconds

Description

MS = milliseconds(X) returns an array of milliseconds equivalent to the values in X. The input and output arrays can contain noninteger values.

  • If X is a numeric array, then milliseconds converts it to a duration array where each element is equal to the number of milliseconds in the corresponding element of X. Then milliseconds sets the Format property of the output array to 's', displaying time in seconds.

  • If X is a duration array, then milliseconds converts it to a double array where each element is equal to the number of milliseconds in the corresponding element of X.

example

Examples

collapse all

Create a numeric array of four integers between 1 and 999.

X = randi(999,1,4)
X = 1×4

   814   905   127   913

To treat the elements of the numeric array as representing time in milliseconds, use the milliseconds function. The output is a duration array.

MS = milliseconds(X)
MS = 1×4 duration
   0.814 sec   0.905 sec   0.127 sec   0.913 sec

To display the duration array in a digital timer format that shows hours, minutes, and seconds to the millisecond, set its Format property to "hh:mm:ss.SSS".

MS.Format = "hh:mm:ss.SSS"
MS = 1×4 duration
   00:00:00.814   00:00:00.905   00:00:00.127   00:00:00.913

Create a duration array.

X = minutes(1) + seconds([0 1 2 3.005])
X = 1×4 duration
        1 min   1.0167 min   1.0333 min   1.0501 min

Display X in seconds instead of minutes.

X.Format = "s"
X = 1×4 duration
       60 sec       61 sec       62 sec   63.005 sec

Convert the elements of X to the equivalent number of milliseconds. The output is a double array.

MS = milliseconds(X)
MS = 1×4

       60000       61000       62000       63005

Input Arguments

collapse all

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

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | duration | logical

Output Arguments

collapse all

Output array, returned as a duration array or double array.

Extended Capabilities

expand all

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Version History

Introduced in R2015a