How can I determine which values in vector X are NOT in vector Y?

14 ビュー (過去 30 日間)
Lewis Foggie
Lewis Foggie 2020 年 4 月 6 日
コメント済み: Birdman 2020 年 4 月 6 日
Consider:
x = [10 20 30]
y = [10 5 20 30]
What's the simplest way you can think of to output a vector Z which tells you which vectors in y appear in x...
Z = [1 0 1 1]
So Z tells you that 10 appears in y and x, 5 appears in y but not x, 20 appears in y and x, 30 appears in y and x.

回答 (1 件)

Birdman
Birdman 2020 年 4 月 6 日
編集済み: Birdman 2020 年 4 月 6 日
Z=~ismember(x,y)
It will return
0 0 0
which means every element in vector X are also in vector Y.
  2 件のコメント
Lewis Foggie
Lewis Foggie 2020 年 4 月 6 日
Awesome, thank you!!
Birdman
Birdman 2020 年 4 月 6 日
You are welcome.

サインインしてコメントする。

カテゴリ

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

タグ

製品


リリース

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by