Set Operations

MATLAB has no dedicated set data type—a “set” here is just a Matlab Array whose elements may be of any data type.

Functions

MATLAB also has no operators for set operations; they are realized through plain functions.

FunctionsDescription
intersectSet intersection of two arrays
ismemberArray elements that are members of set array
setdiffSet difference of two arrays
setxorSet exclusive OR of two arrays
unionSet union of two arrays
uniqueUnique values in array
ismembertolMembers of set within tolerance
uniquetolUnique values within tolerance
joinCombine two tables or timetables by rows using key variables
innerjoinInner join between two tables or timetables
outerjoinOuter join between two tables or timetables

Tolerance

  • A common pitfall in MATLAB is that floating-point precision rarely lets two values be exactly equal; the ...tol functions accept a permitted error
  • Default tolerances are
    • For single: 1e-6
    • For double: 1e-12