If statement with OR operator to create error message for a function

1 回表示 (過去 30 日間)
LivingTheScienceDream
LivingTheScienceDream 2013 年 10 月 21 日
編集済み: Cedric 2013 年 10 月 21 日
Hi
I have a function that has a second input that must be 8, 12 or 16. I want to have an error message to flag when the 2nd input does not take these values. I have tried doing this in an if statement:
if A~=8 || A~=12 || A~=16
error('..','...')
end
Of course, I think my logic here is wrong (if the input is 12, it is true for the A~=8 or 16) and so the if statement is always true and can never be false. Would an AND/OR work (if these exist in matlab)?
Is there a way I can do this in an if statement? Or is there a better way of writing what I'm trying to do?
Thanks for your help!

採用された回答

Cedric
Cedric 2013 年 10 月 21 日
編集済み: Cedric 2013 年 10 月 21 日
if A~=8 && A~=12 && A~=16
error('..','...') ;
end
you could also use ISMEMBER:
if ~ismember(A, [8, 12, 16])
error('..','...') ;
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSignal Generation and Preprocessing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by