フィルターのクリア

Niggle with a ``simple'' if-else structure.

2 ビュー (過去 30 日間)
Caroline Voloshin
Caroline Voloshin 2013 年 7 月 18 日
Hi.
I want to enforce the following structure in MATLAB -
if a>20
{Statement set 1}
elseif 10<a<20
{Statement set 2}
else
{Statement set 3}
end
`a' can take only positive values, from 1 to 30.
My syntax for `elseif' might be wrong, but atleast in this post it clarifies what I'm trying to do :
1) if a > 20, execute statement set 1.
2) if a lies between 10 and 20, execute statement set 2.
3) if a < 10, execute statement set 3.
The problem is, it executes statement set 2 even if a < 10, probably because 10<a<20 is not allowed as an elseif condition.
Is there any other way of enforcing this structure in MATLAB? Or, can someone please suggest a correct `elseif' condition for this purpose.
Thanks.

採用された回答

David Sanchez
David Sanchez 2013 年 7 月 18 日
Instead of
elseif 10<a<20
do the following:
elseif ( (a>10) && (a<20) )
  2 件のコメント
David Sanchez
David Sanchez 2013 年 7 月 18 日
if you want a to be greater or equal to 10 and lessor equal to 20:
elseif ( (a>=10) && (a<=20) )
Caroline Voloshin
Caroline Voloshin 2013 年 7 月 18 日
Thank you very much.
:)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by