W3cubDocs

/Octave

27 Sets

Octave has a number of functions for managing sets of data. A set is defined as a collection of unique elements and is typically represented by a vector of numbers sorted in ascending order. Any vector or matrix can be converted to a set by removing duplicates through the use of the unique function. However, it isn’t necessary to explicitly create a set as all of the functions which operate on sets will convert their input to a set before proceeding.

unique (x)
unique (x, "rows")
[y, i, j] = unique (…)
[y, i, j] = unique (…, "first")
[y, i, j] = unique (…, "last")

Return the unique elements of x sorted in ascending order.

If the input x is a column vector then return a column vector; Otherwise, return a row vector. x may also be a cell array of strings.

If the optional argument "rows" is given then return the unique rows of x sorted in ascending order. The input must be a 2-D matrix to use this option.

If requested, return index vectors i and j such that y = x(i) and x = y(j).

Additionally, if i is a requested output then one of "first" or "last" may be given as an input. If "last" is specified, return the highest possible indices in i, otherwise, if "first" is specified, return the lowest. The default is "last".

See also: union, intersect, setdiff, setxor, ismember.

© 1996–2018 John W. Eaton
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions.
https://octave.org/doc/interpreter/Sets.html