Filter löschen
Filter löschen

Check if all vector elements have same sign

11 Ansichten (letzte 30 Tage)
Oscar Frick
Oscar Frick am 31 Mai 2018
Kommentiert: Oscar Frick am 1 Jun. 2018
Is there an efficient (and easy) way to check if all elements of a vector have the same sign (not caring about zero values)?
I can think of applying sign(v) and checking if all elements is equal to the first one after having removed all elements where sign(v)==0, but this fells somewhat clumsy. Is there an easier or more efficient way?

Akzeptierte Antwort

Stephen23
Stephen23 am 31 Mai 2018
Bearbeitet: Stephen23 am 31 Mai 2018
true if all non-zero elements of V have the same sign:
~any(diff(sign(V(V~=0))))

Weitere Antworten (0)

Kategorien

Mehr zu Deep Learning Toolbox finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by