Compare each element of matrix
Mostrar comentarios más antiguos
I have Matrix A and Matrix B with same dimension size, Matrix C = A-B,I want ot show an error if each element in C<=0, if C>0 execute other commands
Respuestas (1)
Birdman
el 5 de Abr. de 2018
if all(C<=0)
disp('Error');
elseif all(C>0)
%code goes here
end
2 comentarios
siyang hua
el 5 de Abr. de 2018
Birdman
el 6 de Abr. de 2018
Because the resultant C matrix is
C=[1 -2 0]
which neither fits for all(C<=0) nor all(C>0). They both give logical output 0. You may want to create a third statement like:
A = [2 3 4];
B = [1 5 4];
C = A-B;
if all(C<=0)
disp('Error');
elseif all(C>0)
disp('good');
else
disp('none');
end
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!