English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
MATLAB provides various functions for set operations, such as union, intersection, and testing for set membership, etc.
The following table shows some common setting operations-
Serial Number | Function Description |
---|---|
1 | intersect(A,B) Set the intersection of two arrays; return the common values of A and B. The returned values are in sorted order. |
2 | intersect(A,B,'rows') Treat each row of A and each row of B as a single entity, and return the common rows of A and B. The rows of the matrix are returned in sorted order. |
3 | ismember(A,B) Returns an array of the same size as A, containing1(true),if the elements of A are found in B. Elsewhere, it returns 0(false). |
4 | ismember(A,B,'rows') Treat each row of A and each row of B as a single entity, and return containing1(true) vector, where the rows of matrix A are also the rows of B. Elsewhere, it returns 0(false). |
5 | issorted(A) 如果元素按排序顺序排列,则返回逻辑1(true),否则返回逻辑0(false)。输入A可以是向量,也可以是N×1或1×N的字符串单元格数组。如果A和sort(A)的输出相等,则认为A被排序。 |
6 | issorted(A, 'rows') issorted(A)1If the elements are arranged in sorted order, then return logical |
7 | (true), otherwise return logical 0(false). The input A can be a vector or an N× or |
8 | ×N string cell array. If A and sort(A) are equal, then A is considered sorted. issorted(A, 'rows') If the rows of the two-dimensional matrix A are sorted in order, then return logical |
9 | (true), otherwise return logical 0(false). If the output of A and sortrows(A) is equal, then the matrix A is considered sorted. setdiff(A,B) |
10 | Set the difference of two arrays; return the values in A, not in B. The values in the returned array are in sorted order. setdiff(A,B,'rows') |
11 | Treat each row of A and each row of B as a single entity, and return the rows not in B from A. The rows of the returned matrix are in sorted order. The 'rows' option does not support unit arrays. |
Set the xor of two arrays-
Set the union of two arrays7 23 14 15 9 12 8 24 35Unique values in an array unique 2 5 7 8 14 16 25 35 27Unique values in an array Online Example Create a script file and input the following code Examplea = [-
b = [ 7 23 14 15 9 12 8 24 35 ] 2 5 7 8 14 16 25 35 27 u = union(a, b) 2 5 7 8 9 12 14 15 16 23 24 25 27 35 i = intersect(a, b) 7 8 14 35 s = setdiff(a, b) 9 12 15 23 24