@c DO NOT EDIT!  Generated automatically by munge-texi.

@c Copyright (C) 1996, 1997, 2007 John W. Eaton
@c This is part of the Octave manual.
@c For copying conditions, see the file gpl.texi.

@node Sets
@chapter Sets

Octave has a limited set of functions for managing sets of data, where a
set is defined as a collection unique elements.  In Octave a set is
represented as a vector of numbers.

@anchor{doc-create_set}
@deftypefn {Function File} {} create_set (@var{x})
Return a row vector containing the unique values in @var{x}, sorted in
ascending order.  For example,

@example
@group
create_set ([ 1, 2; 3, 4; 4, 2 ])
@result{} [ 1, 2, 3, 4 ]
@end group
@end example
@seealso{union, intersection, complement}
@end deftypefn


@anchor{doc-unique}
@deftypefn {Function File} {} unique (@var{x})

Return the unique elements of @var{x}, sorted in ascending order.
If @var{x} is a row vector, return a row vector, but if @var{x}
is a column vector or a matrix return a column vector.

@deftypefnx {Function File} {} unique (@var{A}, 'rows')

Return the unique rows of @var{A}, sorted in ascending order.

@deftypefnx {Function File} {[@var{y}, @var{i}, @var{j}] = } unique (@var{x})

Return index vectors @var{i} and @var{j} such that @code{x(i)==y} and
@code{y(j)==x}.
@seealso{union, intersect, setdiff, setxor, ismember}
@end deftypefn


@menu
* Set Operations:: 
@end menu

@node Set Operations
@section Set Operations

Octave supports the basic set operations.  That is, Octave can compute
the union, intersection, complement, and difference of two sets.
Octave can also supports the @emph{Exclusive Or} set operation, and
membership determination.  The functions for set operations all work in
pretty much the same way.  As an example, assume that @code{x} and
@code{y} contains two sets, then

@example
union(x, y)
@end example

@noindent
computes the union of the two sets.

@anchor{doc-ismember}
@deftypefn {Function File} {} ismember (@var{A}, @var{S})
Return a matrix the same shape as @var{A} which has 1 if
@code{A(i,j)} is in @var{S} or 0 if it isn't.
@seealso{unique, union, intersection, setxor, setdiff}
@end deftypefn


@anchor{doc-union}
@deftypefn {Function File} {} union (@var{x}, @var{y})
Return the set of elements that are in either of the sets @var{x} and
@var{y}.  For example,

@example
@group
union ([ 1, 2, 4 ], [ 2, 3, 5 ])
@result{} [ 1, 2, 3, 4, 5 ]
@end group
@end example
@seealso{create_set, intersection, complement}
@end deftypefn


@anchor{doc-intersect}
@deftypefn {Function File} {} intersect (@var{a}, @var{b})
@deftypefnx {Function File} {[@var{c}, @var{ia}, @var{ib}] =} intersect (@var{a}, @var{b})

Return the elements in both @var{a} and @var{b}, sorted in ascending
order. If @var{a} and @var{b} are both column vectors return a column
vector, otherwise return a row vector.

Return index vectors @var{ia} and @var{ib} such that @code{a(ia)==c} and
@code{b(ib)==c}.

@end deftypefn
@seealso{unique, union, setxor, setdiff, ismember}


@anchor{doc-complement}
@deftypefn {Function File} {} complement (@var{x}, @var{y})
Return the elements of set @var{y} that are not in set @var{x}.  For
example,

@example
@group
complement ([ 1, 2, 3 ], [ 2, 3, 5 ])
@result{} 5
@end group
@end example
@seealso{create_set, union, intersection}
@end deftypefn


@anchor{doc-setdiff}
@deftypefn {Function File} {} setdiff (@var{a}, @var{b})
@deftypefnx {Function File} {} setdiff (@var{a}, @var{b}, "rows")
Return the elements in @var{a} that are not in @var{b}, sorted in
ascending order.  If @var{a} and @var{b} are both column vectors
return a column vector, otherwise return a row vector.

Given the optional third argument @samp{"rows"}, return the rows in
@var{a} that are not in @var{b}, sorted in ascending order by rows.
@seealso{unique, union, intersect, setxor, ismember}
@end deftypefn


@anchor{doc-setxor}
@deftypefn {Function File} {} setxor (@var{a}, @var{b})

Return the elements exclusive to @var{a} or @var{b}, sorted in ascending
order. If @var{a} and @var{b} are both column vectors return a column
vector, otherwise return a row vector.

@seealso{unique, union, intersect, setdiff, ismember}
@end deftypefn

