MATLAB的ismember
时间: 2023-06-26 10:06:23 浏览: 101
MATLAB的ismember函数用于判断一个数组中的元素是否在另一个数组中出现过,返回一个逻辑数组。它的语法如下:
`[Lia,Locb] = ismember(A,B)`
其中,A和B都是数组,Lia是一个与A相同大小的逻辑数组,表示A中的元素是否在B中出现过,Locb是一个与A相同大小的数组,表示A中的元素在B中第一次出现的位置。如果A中的元素在B中没有出现过,则Locb对应的元素为0。
举个例子,假设有两个数组A和B:
```
A = [1 3 5 7 9];
B = [2 4 6 8 10];
```
使用ismember函数判断A中的元素是否在B中出现过:
```
[Lia,Locb] = ismember(A,B);
Lia =
0 0 0 0 0
Locb =
0 0 0 0 0
```
由于A中的元素都没有在B中出现过,所以Lia和Locb都是0。
相关问题
matlab ismember
`ismember` is a function in MATLAB that checks if elements of one array are present in another array and returns a logical array indicating the result. It takes two input arrays and returns a logical array of the same size as the first input array.
Here is an example usage of `ismember`:
```matlab
A = [1, 2, 3, 4, 5];
B = [3, 4, 6];
tf = ismember(A, B);
```
In this example, `tf` will be a logical array `[0, 0, 1, 1, 0]`, indicating that the elements of `A` that are present in `B` are `3` and `4`.
matlab ismember函数
ismember函数是MATLAB中的一个用于判断一个数组中的元素是否在另一个数组中出现的函数。它的语法为:
[C,ia] = ismember(A,B)
其中A和B都是数组,C是一个逻辑数组,表示A中的每个元素是否在B中出现,ia是一个索引数组,表示A中每个元素在B中第一次出现的位置。如果A中的元素在B中没有出现,则ia对应的值为0。
举个例子,如果有两个数组A和B:
A = [1 2 3 4 5];
B = [3 4 5 6 7];
那么调用ismember函数:
[C,ia] = ismember(A,B)
得到的结果为:
C = [0 0 1 1 1]
ia = [0 0 1 2 3]
这表示A中的第3、4、5个元素在B中出现了,而第1、2个元素没有在B中出现。ia数组中的1、2、3分别对应着A中第3、4、5个元素在B中第一次出现的位置,而1、2对应着A中第1、2个元素在B中没有出现。