how to replace "&&" in a loop
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I would like not to use "&&" in this loop:
if a=x && b=y
d=2
end
how can i replace it?
0 Kommentare
Antworten (1)
Adam Danz
am 6 Mär. 2020
Bearbeitet: Adam Danz
am 6 Mär. 2020
"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 Kommentare
Adam Danz
am 6 Mär. 2020
The original code would throw an error at if a=x but I'll up date my answer to cover the indexing interpretation.
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!