multiple logical operators in if statement
古いコメントを表示
Hi, I have a quick question. Is it possible to write multiple logical conditions in if statement like this;
if
(s < (3 * a + b) * 0.25) || (s > b) ||...
(mflag) && (abs(s-b) >= (abs(b-c) * 0.5)) ||...
(~mflag) && (abs(s-b) >= (c-d) * 0.5) ||...
(mflag) && (abs(b-c) < tol) ||...
(~mflag) && (abs(c-d) < tol)
% bisection method
s = (a+b)*0.5;
mflag = true;
else
mflag = false;
end
採用された回答
その他の回答 (1 件)
Walter Roberson
2017 年 1 月 17 日
3 投票
Certainly.
Note: && has higher priority than || so your sections THIS && THAT || SOMETHING && SOMETHINGELSE would be evaluated as (THIS && THAT) || (SOMETHING && SOMETHINGELSE)
カテゴリ
ヘルプ センター および File Exchange で Operators and Elementary Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!