Using OR between elements in vector or antithesis of any(x)

1 Ansicht (letzte 30 Tage)
Eric Junaeus
Eric Junaeus am 1 Mär. 2021
Kommentiert: Stephen23 am 2 Mär. 2021
Is there a way to use an or command such as | between elements in a vector?
Alternatively:
Rather than use any(x) is there an antithetical command that returns true if any element of the vectorx is zero?
  1 Kommentar
Stephen23
Stephen23 am 2 Mär. 2021
"is there an antithetical command that returns true if any element of the vectorx is zero?"
~all(x)
will be simpler and more efficient than anything else.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Star Strider
Star Strider am 1 Mär. 2021
Not certain what you wnat.
Try these (the any call is there for comparison only):
x = randi([-5 5], 1, 10);
TF1 = any(x == 0);
TF2 = find(x==0)>0;
There may be other options as well.
  2 Kommentare
Eric Junaeus
Eric Junaeus am 1 Mär. 2021
Thanks for the reply!
I tried to make a while loop that would search for any element that's equal to zero in my vector.
It seemed to work with the any command you posted.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by