Main Content

ismember

(Not Recommended) Dataset array elements that are members of set

The dataset data type is not recommended. To work with heterogeneous data, use the MATLAB® table data type instead. See MATLAB table documentation for more information.

Description

LiA = ismember(A,B) for dataset arrays A and B returns a vector of logical values the same length as A. The output vector, LiA, has value 1 (true) in the elements that correspond to observations in A that are also present in B, and 0 (false) otherwise.

LiA = ismember(A,B,vars) returns a vector of logical values the same length as A. The output vector, LiA, has value 1 (true) in the elements that correspond to observations in A that are also present in B for the variables specified in vars only, and 0 (false) otherwise.

[LiA,LocB] = ismember(___) also returns a vector the same length as A containing the index to the first observation in B that corresponds to each observation in A, or 0 if there is no such observation. You can use any of the previous input arguments.

Input Arguments

collapse all

Query array, containing the observations to be found in B, specified as a dataset array.

Set array, specified as a dataset array. When an observation in A is found in B, for all variables or only those variables specified in vars, the corresponding element of LiA is 1.

Variables, specified as a string array or cell array of character vectors containing variable names, or a vector of integers containing variable column numbers. vars indicates which variables to match observations on in A and B.

Output Arguments

collapse all

Indicators whether observations from the query array A are members of the set array B, returned as a vector of logical values the same length as A. LiA has value 1 (true) when the corresponding observation in A is present in B. Otherwise, LiA has value 0 (false).

If you specify vars, LiA has value 1 when the corresponding observation in A is present in B for the variables in vars only.

Index to the first observation in B that corresponds to each observation in A, returned as a vector of the same length as A, for all variables or only those variables specified in vars.

Data Types: logical

Version History

Introduced in R2012b