Comparing a value against a set of values

1 次查看(过去 30 天)
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 中查找有关 Just for fun 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by