필터 지우기
필터 지우기

determine all cells are non-zero within a matrix

조회 수: 1 (최근 30일)
Peng Zhao
Peng Zhao 2019년 7월 3일
댓글: Peng Zhao 2019년 7월 3일
I am trying to determine if all of the numbers in "x" is non-zero values:
x = [1 1 0]
% 1:
if x ~= [0 0 0]
disp('x is not zeros')
end
% 2:
if all(x ~= 0)
disp('x is not zeros')
end
but the output is saying the x is zeros.
what mistake did I make?
  댓글 수: 4
Adam
Adam 2019년 7월 3일
And why isn't this the expected answer? You are testing if all elements of Pref_Color are not equal to 0. Clearly this is false because the final element is 0 therefore it drops into your else block and reports 'no'.
Peng Zhao
Peng Zhao 2019년 7월 3일
Thanks for pointing out.
it should be
if ~all(Pref_Color == 0)
and now it is doing what I expected.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2019년 7월 3일
Your second if statement is correct, and I get the correct output (none).

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by