how to replace "&&" in a loop
조회 수: 2 (최근 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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!