SIVAKUMAR
SIVAKUMAR

Reputation: 1

Matlab-How to perform logical AND operation in single matrix

Hi I have 4x4 matrix which need to perform AND operations in 2x2,3x3 and 4x4. How to perform it in matlab.

I have tried this code.

 R2=and(var(1,:),var(2,:))

R2 =

 1     1     1     1
 1     1     0     1
 1     0     1     0
 1     1     0     0

First 2x2 ans is 1 1 second 3x3 ans is 1 0 0 last 4x4 ans is 1 0 0 0.

Upvotes: 0

Views: 63

Answers (1)

Finn
Finn

Reputation: 2343

all() checks if none of the elements of the vector are zero. On matrizes it returns the vector of hte first non-singleton dimension so you have to do it twice.

for i=2:4
    all( all(R2(1:i,1:i)) )
end

Upvotes: 1

Related Questions