Method Reference: calendarDuration.unique

calendarDuration: B = unique (A)
calendarDuration: B = unique (A, setOrder)
calendarDuration: B = unique (A, occurrence)
calendarDuration: B = unique (A, setOrder, occurrence)
calendarDuration: B = unique (A, occurrence, setOrder)
calendarDuration: B = unique (A, …, 'rows')
calendarDuration: [B, ixA, ixB] = unique (…)

Unique values in a calendarDuration array.

B = unique (A) returns the unique values of the calendarDuration array A in sorted order.

B = unique (A, setOrder) returns the unique values of the calendarDuration array A in an order as specified by setOrder, which can be either of the following values:

  • 'sorted' (default) returns the unique values sorted in ascending order.
  • 'stable' returns the unique values according to their order of occurrence.

B = unique (A, occurrence) returns the unique values of the calendarDuration array tblA according to their order of occurrence. occurrence can be either of the following values:

  • 'first' (default) returns the first occurrence of each unique value, i.e. the lowest possible indices are returned.
  • 'last' returns the last occurrence of each unique value, i.e. the highest possible indices are returned.

You can specify setOrder and occurrence arguments together.

B = unique (A, …, 'rows') returns the unique rows of A by treating each row as a single entity. The 'rows' option can be used alone or in any combination with the setOrder and occurrence arguments. 'rows' can be placed at any position in the function’s argument list after the input array A. However, this syntax is only valid for 2-dimensional calendarDuration arrays.

[tblB, ixA, ixB] = unique (…) also returns index vectors ixA and ixB using any of the previous syntaxes. ixA and ixB map the arrays A and B to one another such that B = A(ixA) and A = B(ixB). When the 'rows' optional argument is specified, then B = A(ixA,:) and tblA = tblB(ixB,:).

Source Code: calendarDuration

Example: 1

unique returns the distinct calendar durations in an array (equivalent spans count as one).

 d = calmonths ([1, 13, 1, 25, 13])
d =
  1x5 calendarDuration array

    1mo    1y 1mo    1mo    2y 1mo    1y 1mo
 unique (d)
ans =
  1x3 calendarDuration array

    1mo    1y 1mo    2y 1mo