필터 지우기
필터 지우기

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))))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by