Categories &

Functions List

Class Definition: duration

datatypes: duration

Array representing durations of time using fixed-length time units.

duration values are stored internally as double type array representing numbers of elapsed days as a fixed-length time unit. By default, fractional seconds of duration values are not displayed, but their actual precision is closer to nanoseconds for typical time lengths.

duration arrays can be created through their constructor by combining numeric arrays representing individual fixed-length elapsed time units or through the functions years, days, hours, minutes, seconds, and calyears, which create fixed-length durations in terms of a single duration units. These functions are also available as methods of duration arrays to extract individual duration units as numeric arrays.

See also: calendarDuration, datetime

Source Code: duration

Properties

Display format, specified as a character vector or string scalar. If specified as a string scalar, it is converted and stored internally as a character vector.

Methods

duration: D = duration (X)
duration: D = duration (H, MI, S)
duration: D = duration (H, MI, S, MS)
duration: D = duration (TimeStrings)
duration: D = duration (TimeStrings, 'InputFormat', INFMT)
duration: D = duration (…, 'Format', FMT)

D = duration (X) creates a column vector of durations from a numeric matrix.

D = duration (H, MI, S) creates a duration array from numeric arrays containing the number of hours, minutes, and seconds specified by H, MI and S, respectively.

D = duration (H, MI, S, MS) creates a duration array from numeric arrays containing the number of hours, minutes, seconds, and milliseconds specified by H, MI, S, and MS, respectively.

D = duration (TimeStrings) creates a duration array from text that represents elapsed times. TimeStrings can be a character vector, a cell array of character vectors, or a string array representing times using either the 'hh:mm:ss' or the 'dd:hh:mm:ss' format.

D = duration (TimeStrings, 'InputFormat', INFMT) creates a duration array from text that represents elapsed times according to the format specified by INFMT, which can be any of the following:

  • 'dd:hh:mm:ss'
  • 'hh:mm:ss'
  • 'mm:ss'
  • 'hh:mm'
  • Any of the first three formats can also be appended with up to nine S characters to indicate fractional second digits, such as 'dd:hh:mm:ss.SS' or 'mm:ss.SS'.

D = duration (…, 'Format', FMT) specifies the format in which D is displayed. FMT can specify either a digital timer, which can have any of the valid formats for 'InputFormat' as shown above or a single number with time units by specifying one of the following:

  • 'y' fixed-length years (1 year equals 365.2425 days)
  • 'd' fixed-length days (1 day equals 24 hours)
  • 'h' hours
  • 'm' minutes
  • 's' seconds

D = duration () returns a scalar array of durations with an elapsed time value of zero. To create an empty duration array, use duration ([], [], []).

See also: years, days, hours, minutes, seconds, milliseconds, duration, isduration, calendarDuration, datetime

duration: cstr = dispstrings (D)

cstr = dispstrings (D) returns a cellstr array of character vectors, cstr, which has the same size as the input duration D.

duration: cstr = cellstr (D)
duration: cstr = cellstr (D, Format)

cstr = cellstr (D) returns a cellstr array of character vectors, cstr, which has the same size as the input duration D.

duration: cmat = char (D)

cmat = char (D) returns a character matrix with one row per element in D.

duration: DV = datevec (DT)
duration: [Y, MO, D, h, mi, s] = datevec (DT)

DV = datevec (DT) returns an N×6 numeric matrix whose rows represent each element in DT and each column corresponds to years, months, days, hours, minutes, and seconds, respectively. Since months cannot be represented as a fixed length of time, the second column of DV is always zero. DV represents a length of time split accross different fixed-length elapsed time units.

[Y, MO, D, h, mi, s] = datevec (DT) returns the components of DT as individual variables, but unlike DV in the previous syntax, each variable has the same size as the duration array DT.

duration: H = hms (D)
duration: [H, M] = hms (D)
duration: [H, M, S] = hms (D)

[H, M, S] = hms (D) splits the duration array D into separate numeric arrays H, M, and S, which correspond to hours, minutes, and seconds, repsectively. Hours and minutes are returned as whole numbers, while seconds may also have a fractional part.

duration: X = years (D)

X = years (D) converts durations in D to the equivalent number of fixed-length years (1 year equals 365.2425 days). X is a double array of the same size as D.

duration: X = days (D)

X = days (D) converts durations in D to the equivalent number of fixed-length days (1 day equals 24 hours). X is a double array of the same size as D.

duration: X = hours (D)

X = hours (D) converts durations in D to the equivalent number of hours. X is a double array of the same size as D.

duration: X = minutes (D)

X = minutes (D) converts durations in D to the equivalent number of minutes. X is a double array of the same size as D.

duration: X = seconds (D)

X = seconds (D) converts durations in D to the equivalent number of seconds. X is a double array of the same size as D.

duration: X = milliseconds (D)

X = milliseconds (D) converts durations in D to the equivalent number of milliseconds. X is a double array of the same size as D.

duration: sz = size (D)
duration: dim_sz = size (D, dim)
duration: dim_sz = size (D, d1, d2, …)
duration: [rows, columns, …, dim_n_sz] = size (…)

sz = size (D) returns a row vector with the size (number of elements) of each dimension for the duration array D.

dim_sz = size (D, dim) returns the size of the corresponding dimension specified in dim. If dim is a vector, then dim_sz is a vector of the same length and with each element corresponding to a specified dimension. Multiple dimensions may also be specified as separate arguments.

With a single output argument, size returns a row vector. When called with multiple output arguments, size returns the size of dimension N in the Nth argument.

duration: out = ndims (D)

out = ndims (D) returns the number of dimensions of the duration array D.

duration: out = numel (D)

For compatibility reasons with Octave’s OOP interface and subsasgn behavior, duration’s numel is defined to always return 1.

duration: out = nnz (D)

out = nnz (D) returns the number of nonzero elements in the duration array D.

duration: N = length (D)

N = length (D) returns the size of the longest dimension of the duration array D, unless any of its dimensions has zero length, in which case length (D) returns 0.

duration: hey = keyHash (D)

h = keyHash (D) generates a uint64 scalar that represents the input array D. keyHash utilizes the 64-bit FMV-1a variant of the Fowler-Noll-Vo non-cryptographic hash function.

h = keyHash (D), base also generates a 64-bit hash code using base as the offset basis for the FNV-1a hash algorithm. base must be a uint64 integer type scalar. Use this syntax to cascade keyHash on multiple objects for which a single hash code is required.

Note that unlike MATLAB, this implementation does no use any random seed. As a result, keyHash will always generate the exact same hash key for any particular input across different workers and Octave sessions.

duration.isbetween is not documented.
duration: TF = iscolumn (D)

TF = iscolumn (D) returns a logical scalar TF, which is true if the duration array D is a column vector and false otherwise. A column vector is a 2-D array for which size (X) returns [N, 1] with non-negative N.

duration: TF = isempty (D)

TF = isempty (D) returns a logical scalar TF, which is true if the duration array D is empty and false otherwise.

duration.isequal is not documented.
duration.isequaln is not documented.
duration.isfinite is not documented.
duration.isinf is not documented.
duration: TF = ismatrix (D)

TF = ismatrix (D) returns a logical scalar TF, which is true if the duration array D is a matrix and false otherwise. A matrix is an array of any type where ndims (X) == 2 and for which size (X) returns [H, W] with non-negative H and W.

duration: TF = ismatrix (D)

TF = ismatrix (D) returns a logical scalar TF, which is true if the duration array D is a matrix and false otherwise. A matrix is an array of any type where ndims (X) == 2 and for which size (X) returns [H, W] with non-negative H and W.

duration.ismissing is not documented.
duration.isnan is not documented.
duration: TF = isrow (D)

TF = isrow (D) returns a logical scalar TF, which is true if the duration array D is a row vector and false otherwise. A row vector is a 2-D array for which size (X) returns [1, N] with non-negative N.

duration: TF = isscalar (D)

TF = isscalar (D) returns a logical scalar TF, which is true if the duration array D is also a scalar and false otherwise. A scalar is a single element object for which size (X) returns [1, 1].

duration.issorted is not documented.
duration.issortedrows is not documented.
duration: TF = isvector (D)

TF = isvector (D) returns a logical scalar TF, which is true if the duration array D is a vector and false otherwise. A vector is a 2-D array for which one of the dimensions is equal to 1 (either 1×N or N×1). By definition, a scalar is also a vector.

duration.eq is not documented.
duration.ge is not documented.
duration.gt is not documented.
duration.le is not documented.
duration.lt is not documented.
duration.ne is not documented.
duration.abs is not documented.
duration.plus is not documented.
duration.uplus is not documented.
duration.minus is not documented.
duration.uminus is not documented.
duration.times is not documented.
duration.mtimes is not documented.
duration.ldivide is not documented.
duration.mldivide is not documented.
duration.rdivide is not documented.
duration.mrdivide is not documented.
duration.colon is not documented.
duration.linspace is not documented.
duration.sum is not documented.
duration.cumsum is not documented.
duration.diff is not documented.
duration.mean is not documented.
duration.median is not documented.
duration.mode is not documented.
duration.floor is not documented.
duration.ceil is not documented.
duration.round is not documented.
duration.sign is not documented.
duration.sort is not documented.
duration.sortrows is not documented.
duration.sortrows is not documented.
duration.interp1 is not documented.
duration.intersect is not documented.
duration.setdiff is not documented.
duration.setxor is not documented.
duration.union is not documented.
duration: C = cat (dim, A, B, …)

C = cat (dim, A, B, …) concatenates duration arrays A, B, … along dimension dim. All input arrays must have the same size except along the operating dimension dim. Any of the input arrays may also be string arrays or cell arrays of character vectors of compatible size. Additionally, an input can be a numeric matrix, which when parsed to the constructor will return a duration array of compatible size.

duration: C = horzcat (A, B, …)

C = horzcat (A, B, … is the equivalent of the syntax B = [A, B, …] and horizontally concatenates the duration arrays A, B, …. All input arrays must have the same size except along the second dimension. Any of the input arrays may also be string arrays or cell arrays of character vectors of compatible size. Additionally, an input can be a numeric matrix, which when parsed to the constructor will return a duration array of compatible size.

duration: C = vertat (A, B, …)

C = vertat (A, B, … is the equivalent of the syntax B = [A; B; …] and vertically concatenates the duration arrays A, B, …. All input arrays must have the same size except along the first dimension. All of the input arrays may also be string arrays or cell arrays of character vectors of compatible size. Additionally, an input can be a numeric matrix, which when parsed to the constructor will return a duration array of compatible size.

duration: B = repmat (A, n)
duration: B = repmat (A, d1, …, dN)
duration: B = repmat (A, dimvec)

B = repmat (A, n) returns a duration array B containing n copies of the input duration array A along every dimension of A.

B = repmat (A, d1, …, dN) returns an array B containing copies of A along the dimensions specified by the list of scalar integer values d1, …, dN, which specify how many copies of A are made in each dimension.

B = repmat (A, dimvec) is equivalent to the previous syntax with dimvec = [d1, …, dN].

duration: B = repelem (A, n)
duration: B = repelem (A, d1, …, dN)

B = repelem (A, n) returns a duration vector B containing repeated elements of the input A, which must be a duration vector. If n is a scalar, each element of A is repeated n times along the non-singleton dimension of A. If n is a vector, it must have the same elemnts as A, in which case it specifies the number of times to repeat each corresponding element of A.

B = repelem (A, d1, …, dN returns an array B with each element of A repeated according to the the list of input arguments d1, …, dN each corresponding to a different dimension 1:ndims (A) of the input array A. d1, …, dN must be either scalars or vectors with the same length as the corresponding dimension of A containing non-negative integer values specifying the number of repetitions of each element along the corresponding dimension.

duration: B = repelems (A, R)

B = repelems (A, R) returns a duration vector B containing repeated elements of the input A, which must be a duration vector. R must be a 2×N matrix of integers. Entries in the first row of R correspond to the linear indexing of the elements in A to be repeated. The corresponding entries in the second row of R specify the repeat count of each element.

duration: B = reshape (A, d1, …, dN)
duration: B = reshape (A, …, [], …)
duration: B = reshape (A, dimvec)

B = reshape (A, d1, …, dN) returns a duration array B with specified dimensions d1, …, dN, whose elements are taken columnwise from the duration array A. The product of d1, …, dN must equal the total number of elements in A.

B = reshape (A, …, [], …) returns a duration array B with one dimension unspecified which is calculated automatically so that the product of dimensions in B matches the total elements in A, which must be divisible the product of specified dimensions. An empty matrix ([]) is used to flag the unspecified dimension.

duration: B = circshift (A, n)
duration: B = circshift (A, n, dim)

B = circshift (A, n) circularly shifts the elements of the duration array A according to n. If n is a nonzero integer scalar, then the elements of A are shifted by n elements along the first non-singleton dimension of A. If n is a vector, it must not be longer that the number of dimensions of A with each value of n corresponding to a dimension in A. The sign of the value(s) in n specify the direction in the elements of A are shifted.

B = circshift (A, n, dim) circularly shifts the elements of the duration array A along the dimension specified by dim. In this case, n must be a scalar integer value.

duration: B = permute (A, dims)

B = permute (A, dims) returns the generalized transpose of the duration array A by rearranging its dimensions according to the permutation vector specified in dims.

dims must index all the dimensions 1:ndims (A) of the input array A, in any order, but only once. The Nth dimension of A gets remapped to the dimension in B specified by dims(N).

duration: A = ipermute (B, dims)

A = ipermute (B, dims) returns the inverse of the generalized transpose performed by the permute function. The expression ipermute (permute (A, dims), dims) returns the original array A.

dims must index all the dimensions 1:ndims (B) of the input array B, in any order, but only once. The dimension of B specified in dims(N) gets remapped to the Nth dimension of A.

duration: B = transpose (A)

B = transpose (A) is the equivalent of the syntax B = A.' and returns the transpose of the duration matrix A.

duration: B = ctranspose (A)

B = ctranspose (A) is the equivalent of the syntax B = A' and returns the transpose of the duration matrix A. For duration arrays, ctranspose is identical to transpose.