ismember matlab

ismember 判断A中的元素在B中有没有出现

LIA = ismember(A,B) for arrays A and B returns an array of the same size as A containing true where the elements of A are in B and false otherwise.

对于数组A合B,返回一个和A同样尺寸的数组,若A某位置的元素在B中出现,则LIA相应位置为true,否则为false

LIA = ismember(A,B,'rows') for matrices A and B with the same number of columns, returns a vector containing true where the rows of A are also rows of B and false otherwise.

对于具有同样列数的A和B,返回一个向量,行数和A相同,如果A的该行在B中出现,则LIA该行的值为1,如果A的该行在B中没有出现过,返回0

[LIA,LOCB] = ismember(A,B) also returns an array LOCB containing the highest absolute index in B for each element in A which is a member of B and 0 if there is no such index.

LOCB和数组A的大小一样,里面包含A中元素在B中出现的位置,最大绝对值位置,即如果B中有两个元素和A中某元素相同,那么就返回索引值最大的那个位置

[LIA,LOCB] = ismember(A,B,'rows') also returns a vector LOCB containing the highest absolute index in B for each row in A which is a member of B and 0 if there is no such index.

同上

In a future release, the behavior of ismember will change including:

- occurrence of indices in LOCB will switch from highest to lowest

- tighter restrictions on combinations of classes

In order to see what impact those changes will have on your code, use:

[LIA,LOCB] = ismember(A,B,'R2012a')

[LIA,LOCB] = ismember(A,B,'rows','R2012a')

If the changes in behavior adversely affect your code, you may preserve

the current behavior with:

[LIA,LOCB] = ismember(A,B,'legacy')

[LIA,LOCB] = ismember(A,B,'rows','legacy')

Examples:

a = [9 9 8 8 7 7 7 6 6 6 5 5 4 4 2 1 1 1]

b = [1 1 1 3 3 3 3 3 4 4 4 4 4 9 9 9]

[lia1,locb1] = ismember(a,b)

% returns

lia1 = [1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1]

locb1 = [16 16 0 0 0 0 0 0 0 0 0 0 13 13 0 3 3 3]

[lia2,locb2] = ismember(a,b,'R2012a')

% returns

lia2 = [1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1]

locb2 = [14 14 0 0 0 0 0 0 0 0 0 0 9 9 0 1 1 1]

[lia,locb] = ismember([1 NaN 2 3],[3 4 NaN 1])

% NaNs compare as not equal, so this returns

lia = [1 0 0 1], locb = [4 0 0 1]

Class support for inputs A and B, where A and B must be of the same

class unless stated otherwise:

- logical, char, all numeric classes (may combine with double arrays)

- cell arrays of strings (may combine with char arrays)

-- 'rows' option is not supported for cell arrays

- objects with methods SORT (SORTROWS for the 'rows' option), EQ and NE

-- including heterogeneous arrays derived from the same root class