Need an IF boolean that compares a number to all numbers in an array

Hello
a = [1,2,3]
b=2
if b is in a
do this
end
How do i do it?

回答 (1 件)

Matt Fig
Matt Fig 2012 年 11 月 15 日
編集済み: Matt Fig 2012 年 11 月 15 日

0 投票

a = [1,2,3];
b = 2;
if any(b==a)
disp('b in a')
else
disp('b not in a')
end
Also, see the help for ISMEMBER. In this case it is not needed.

この質問は閉じられています。

タグ

質問済み:

2012 年 11 月 15 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by