MATLAB Answers

Pankaj
0

logical operators on a logical matrix

Asked by Pankaj
on 13 Sep 2019
Latest activity Commented on by Pankaj
on 13 Sep 2019
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.

  0 Comments

Sign in to comment.

Products

1 Answer

Answer by madhan ravi
on 13 Sep 2019
 Accepted Answer

all(A,2)
any(A,2)

  4 Comments

Show 1 older comment
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..
Thanks Jos :)
thanks Jos

Sign in to comment.