フィルターのクリア

Check if all vector elements have same sign

11 ビュー (過去 30 日間)
Oscar Frick
Oscar Frick 2018 年 5 月 31 日
コメント済み: Oscar Frick 2018 年 6 月 1 日
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?

採用された回答

Stephen23
Stephen23 2018 年 5 月 31 日
編集済み: Stephen23 2018 年 5 月 31 日
true if all non-zero elements of V have the same sign:
~any(diff(sign(V(V~=0))))
  1 件のコメント
Oscar Frick
Oscar Frick 2018 年 6 月 1 日
That works, thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDeep Learning Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by