logical operators on a logical matrix

Consider the following logical matrix of 4X2
A = logical([1, 0; 1, 1; 0, 0; 0, 1])
I would like to apply logical operator (say `or`, `and`) on the matrix row wise so the result is 4X1 vector. (the matrix could of any dimension say mXn, and I want mX1 as output). The `or` operator requires two matrices for comparision, how to do it for single matrix.

 Respuesta aceptada

madhan ravi
madhan ravi el 13 de Sept. de 2019
all(A,2)
any(A,2)

4 comentarios

Pankaj
Pankaj el 13 de Sept. de 2019
thanks bhai, I did not knew that simple function.
all and any, as used above, will return the row-wise and and or operations quite effectively
in general, you can select the two rows and use
and(A(1,:), A(2,:))
xor(A(1,:), A(2,:))
etc..
madhan ravi
madhan ravi el 13 de Sept. de 2019
Thanks Jos :)
Pankaj
Pankaj el 13 de Sept. de 2019
thanks Jos

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 13 de Sept. de 2019

Comentada:

el 13 de Sept. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by