octave: Set Operations

 
 27.1 Set Operations
 ===================
 
 Octave supports several basic set operations.  Octave can compute the
 union, intersection, and difference of two sets.  Octave also supports
 the _Exclusive Or_ set operation.
 
    The functions for set operations all work in the same way by
 accepting two input sets and returning a third set.  As an example,
 assume that ‘a’ and ‘b’ contains two sets, then
 
      union (a, b)
 
 computes the union of the two sets.
 
    Finally, determining whether elements belong to a set can be done
 with the ‘ismember’ function.  Because sets are ordered this operation
 is very efficient and is of order O(log2(n)) which is preferable to the
 ‘find’ function which is of order O(n).
 
  -- : C = intersect (A, B)
  -- : C = intersect (A, B, "rows")
  -- : [C, IA, IB] = intersect (...)
 
      Return the unique elements common to both A and B sorted in
      ascending order.
 
      If A and B are both row vectors then return a row vector;
      Otherwise, return a column vector.  The inputs may also be cell
      arrays of strings.
 
      If the optional input "rows" is given then return the common rows
      of A and B.  The inputs must be 2-D matrices to use this option.
 
      If requested, return index vectors IA and IB such that ‘C = A(IA)’
      and ‘C = B(IB)’.
 
DONTPRINTYET  See also: Seeunique XREFunique, Seeunion XREFunion, *noteDONTPRINTYET DONTPRINTYET  See also: Seeunique XREFunique, Seeunion XREFunion, See
 setdiff XREFsetdiff, Seesetxor XREFsetxor, *noteismember:
DONTPRINTYET DONTPRINTYET  See also: Seeunique XREFunique, Seeunion XREFunion, See
 setdiff XREFsetdiff, Seesetxor XREFsetxor, Seeismember

 XREFismember.
 
  -- : C = union (A, B)
  -- : C = union (A, B, "rows")
  -- : [C, IA, IB] = union (...)
 
      Return the unique elements that are in either A or B sorted in
      ascending order.
 
      If A and B are both row vectors then return a row vector;
      Otherwise, return a column vector.  The inputs may also be cell
      arrays of strings.
 
      If the optional input "rows" is given then return rows that are in
      either A or B.  The inputs must be 2-D matrices to use this option.
 
      The optional outputs IA and IB are index vectors such that ‘A(IA)’
      and ‘B(IB)’ are disjoint sets whose union is C.
 
      See also: Seeunique XREFunique, Seeintersect XREFintersect,
DONTPRINTYET       Seesetdiff XREFsetdiff, Seesetxor XREFsetxor, *noteDONTPRINTYET       Seesetdiff XREFsetdiff, Seesetxor XREFsetxor, See
      ismember XREFismember.
 
  -- : C = setdiff (A, B)
  -- : C = setdiff (A, B, "rows")
  -- : [C, IA] = setdiff (...)
      Return the unique elements in A that are not in B sorted in
      ascending order.
 
      If A is a row vector return a column vector; Otherwise, return a
      column vector.  The inputs may also be cell arrays of strings.
 
      If the optional input "rows" is given then return the rows in A
      that are not in B.  The inputs must be 2-D matrices to use this
      option.
 
      If requested, return the index vector IA such that ‘C = A(IA)’.
 
DONTPRINTYET       See also: Seeunique XREFunique, Seeunion XREFunion, *noteDONTPRINTYET DONTPRINTYET       See also: Seeunique XREFunique, Seeunion XREFunion, See
      intersect XREFintersect, Seesetxor XREFsetxor, *noteismember:
DONTPRINTYET DONTPRINTYET       See also: Seeunique XREFunique, Seeunion XREFunion, See
      intersect XREFintersect, Seesetxor XREFsetxor, Seeismember

      XREFismember.
 
  -- : C = setxor (A, B)
  -- : C = setxor (A, B, "rows")
  -- : [C, IA, IB] = setxor (...)
 
      Return the unique elements exclusive to sets A or B sorted in
      ascending order.
 
      If A and B are both row vectors then return a row vector;
      Otherwise, return a column vector.  The inputs may also be cell
      arrays of strings.
 
      If the optional input "rows" is given then return the rows
      exclusive to sets A and B.  The inputs must be 2-D matrices to use
      this option.
 
      If requested, return index vectors IA and IB such that ‘A(IA)’ and
      ‘B(IB)’ are disjoint sets whose union is C.
 
DONTPRINTYET       See also: Seeunique XREFunique, Seeunion XREFunion, *noteDONTPRINTYET DONTPRINTYET       See also: Seeunique XREFunique, Seeunion XREFunion, See
      intersect XREFintersect, Seesetdiff XREFsetdiff, *noteDONTPRINTYET DONTPRINTYET       See also: Seeunique XREFunique, Seeunion XREFunion, See
      intersect XREFintersect, Seesetdiff XREFsetdiff, See
      ismember XREFismember.
 
  -- : TF = ismember (A, S)
  -- : TF = ismember (A, S, "rows")
  -- : [TF, S_IDX] = ismember (...)
 
      Return a logical matrix TF with the same shape as A which is true
      (1) if the element in A is found in S and false (0) if it is not.
 
      If a second output argument is requested then the index into S of
      each matching element is also returned.
 
           a = [3, 10, 1];
           s = [0:9];
           [tf, s_idx] = ismember (a, s)
                ⇒ tf = [1, 0, 1]
                ⇒ s_idx = [4, 0, 2]
 
      The inputs A and S may also be cell arrays.
 
           a = {"abc"};
           s = {"abc", "def"};
           [tf, s_idx] = ismember (a, s)
                ⇒ tf = [1, 0]
                ⇒ s_idx = [1, 0]
 
      If the optional third argument "rows" is given then compare rows in
      A with rows in S.  The inputs must be 2-D matrices with the same
      number of columns to use this option.
 
           a = [1:3; 5:7; 4:6];
           s = [0:2; 1:3; 2:4; 3:5; 4:6];
           [tf, s_idx] = ismember (a, s, "rows")
                ⇒ tf = logical ([1; 0; 1])
                ⇒ s_idx = [2; 0; 5];
 
DONTPRINTYET       See also: Seelookup XREFlookup, Seeunique XREFunique, *noteDONTPRINTYET DONTPRINTYET       See also: Seelookup XREFlookup, Seeunique XREFunique, See
      union XREFunion, Seeintersect XREFintersect, *notesetdiff:
DONTPRINTYET DONTPRINTYET       See also: Seelookup XREFlookup, Seeunique XREFunique, See
      union XREFunion, Seeintersect XREFintersect, Seesetdiff

      XREFsetdiff, Seesetxor XREFsetxor.
 
  -- : powerset (A)
  -- : powerset (A, "rows")
      Compute the powerset (all subsets) of the set A.
 
      The set A must be a numerical matrix or a cell array of strings.
      The output will always be a cell array of either vectors or
      strings.
 
      With the optional argument "rows", each row of the set A is
      considered one element of the set.  The input must be a 2-D numeric
      matrix to use this argument.
 
DONTPRINTYET       See also: Seeunique XREFunique, Seeunion XREFunion, *noteDONTPRINTYET DONTPRINTYET       See also: Seeunique XREFunique, Seeunion XREFunion, See
      intersect XREFintersect, Seesetdiff XREFsetdiff, *notesetxor:
DONTPRINTYET DONTPRINTYET       See also: Seeunique XREFunique, Seeunion XREFunion, See
      intersect XREFintersect, Seesetdiff XREFsetdiff, Seesetxor

      XREFsetxor, Seeismember XREFismember.