duration

Methods

Method Reference: duration.sort

duration: B = sort (A)
duration: B = sort (A, dim)
duration: B = sort (A, direction)
duration: B = sort (A, dim, direction)
duration: B = sort (…, 'MissingPlacement', MP)
duration: B = sort (…, 'ComparisonMethod', CM)
duration: [B, index] = sort (A, …)

Sort elements in a duration array.

B = sort (A) sorts the duration array A in ascending order. If A is a matrix, sort (A) sorts each column of A in ascending order. For multidimensional arrays, mode (A) sorts along the first non-singleton dimension.

B = sort (A, dim) sorts along the dimension specified by dim.

B = sort (A, direction) also specifies the sorting direction, which can be either 'ascend' (default) or 'descend'.

B = sort (…, 'MissingPlacement', MP) specifies where to place the missing elements (<undefined>) returned in B with one of the following options specified in MP:

  • 'auto', which is the default, places missing elements last for ascending sort and first for descending sort.
  • 'first' places missing elements first.
  • 'last' places missing elements last.

B = sort (…, 'ComparisonMethod', CM) specifies the comparison method for determining the order of elements returned in B with one of following options:

  • 'auto', which is the default, sorts by real (A).
  • 'real' sorts by real (A).
  • 'abs' sorts by abs (A).

[B, index] = sort (A, …) also returns a sorting index containing the original indices of the elements in the sorted array. index is the same size as A and it comprises indexing vectors oriented along the operating dimensions.

  • If A is a vector, then index contains the original linear indices of the elements in the sorted vector B such that B = A(index).
  • If A is an M×N matrix and dim = 1, then index contains the original row indices of the elements in the sorted vector B such that for j = 1:N, B(:,j) = A(index(:,j),j).

Source Code: duration

Example: 1

sort orders the durations from shortest to longest.

 d = minutes ([180, 30, 90, 45])
d =
  1x4 duration array

    180 min    30 min    90 min    45 min
 sort (d)
ans =
  1x4 duration array

    30 min    45 min    90 min    180 min