how to replace "&&" in a loop
3 ビュー (過去 30 日間)
表示 古いコメント
I would like not to use "&&" in this loop:
if a=x && b=y
d=2
end
how can i replace it?
0 件のコメント
回答 (1 件)
Adam Danz
2020 年 3 月 6 日
編集済み: Adam Danz
2020 年 3 月 6 日
"how to replace "&&" in a loop"
If, for whatever reason, you don't like the && symbols,
if a==x && b==y
d=2;
end
could be rewritten as
if all([a==x,b==y])
or
if all([isequal(a,x), isequal(b,y)])
or perhaps you'd like to use indexing as Stephen pointed out,
idx = a==x & b==y;
d(idx) = 2;
2 件のコメント
Adam Danz
2020 年 3 月 6 日
The original code would throw an error at if a=x but I'll up date my answer to cover the indexing interpretation.
参考
カテゴリ
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!