天天看點

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‘)

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