필터 지우기
필터 지우기

Comparing a value against a set of values

조회 수: 3 (최근 30일)
t4741
t4741 2019년 9월 10일
답변: Bruno Luong 2019년 9월 10일
I have a 1x1xn array of numbers that range from 0-255 (RGB), where n can be any number. Let's call it data.
I want to check if all the values of data are zero. If any of them are non-zero i want it to run a given command, and if they are all zero then I want it to not run the command
How can i do this?

답변 (2개)

Bruno Luong
Bruno Luong 2019년 9월 10일
if any(A,3)
% ...
end

Raj
Raj 2019년 9월 10일
편집: Raj 2019년 9월 10일
A=rand(1,1,n) % Define your matrix here
B=nonzeros(A);
if isempty(B)
%%Do nothing
else
%%Run command here
end
  댓글 수: 2
Andrei Bobrov
Andrei Bobrov 2019년 9월 10일
A=rand(1,1,n) % Define your matrix here
if all(A)
%%Run command here
end
Raj
Raj 2019년 9월 10일
Obviously this is a better solution. Thanks!

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by