How could I check that how many elements of x is inside y?

1 回表示 (過去 30 日間)
VIJENDRA
VIJENDRA 2015 年 9 月 23 日
編集済み: Stephen23 2015 年 9 月 23 日
Suppose I have
x = [2,7,8,11];
and
y = [1,2,4,5,7,8,9,12,15,21,27]
How could I check that how many elements of x is inside y?

採用された回答

Stephen23
Stephen23 2015 年 9 月 23 日
編集済み: Stephen23 2015 年 9 月 23 日
You can use ismember:
>> x = [2,7,8,11];
>> y = [1,2,4,5,7,8,9,12,15,21,27];
>> ismember(x,y)
ans =
1 1 1 0
>> sum(ismember(x,y))
ans = 3

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by