Comparing a value against a set of values

2 visualizaciones (últimos 30 días)
t4741
t4741 el 10 de Sept. de 2019
Respondida: Bruno Luong el 10 de Sept. de 2019
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?

Respuestas (2)

Bruno Luong
Bruno Luong el 10 de Sept. de 2019
if any(A,3)
% ...
end

Raj
Raj el 10 de Sept. de 2019
Editada: Raj el 10 de Sept. de 2019
A=rand(1,1,n) % Define your matrix here
B=nonzeros(A);
if isempty(B)
%%Do nothing
else
%%Run command here
end
  2 comentarios
Andrei Bobrov
Andrei Bobrov el 10 de Sept. de 2019
A=rand(1,1,n) % Define your matrix here
if all(A)
%%Run command here
end
Raj
Raj el 10 de Sept. de 2019
Obviously this is a better solution. Thanks!

Iniciar sesión para comentar.

Categorías

Más información sobre Just for fun en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by