MATLAB Answers


How to apply OR operation to a matrix?

Asked by pietro
on 12 Jul 2014
Latest activity Answered by Roger Stafford
on 12 Jul 2014

Hi folk,

I need to apply the OR operation to the column of a matrix. Here an example:

a=[0 0 1; 0 1 1];
[0 0 1]




1 Answer

Answer by Roger Stafford
on 12 Jul 2014
 Accepted answer

Your example is not the 'OR', it is the 'AND', of the columns. The 'OR' of the columns is done this way:

 b = any(a,1);

The 'AND' would be done this way:

 b = all(a,1);


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!