if statements using logical operators
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
cgo
am 6 Nov. 2015
Beantwortet: Star Strider
am 6 Nov. 2015
Let me define first that: 'distance' is a vector (1 x n) and 'f' is a scalar (1 x 1). Example: distance = [1 10 5]; f = 2. The logical operator: distance > 2 would output: [0 1 1].
I want to say that if the output is NOT all zero, then do X. If the output is all zero, then do Y. How do I translate that to if-then statements?
Thanks for your help.
0 Kommentare
Akzeptierte Antwort
Star Strider
am 6 Nov. 2015
One approach:
if all(distance > f)
sprintf('All distances > %.1f',f)
else
sprintf('Some distances <= %.1f',f)
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical 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!