Tutorial

Logical Operations in MATLAB

MATLAB supports the logical operations AND, OR, NOT, and XOR.

Quick reference

For details on each operation, click the corresponding link.

Table 1. Quick reference of logical operations in MATLAB.
Operation Syntax Details
AND A & B, A && B More info
OR A | B, A || B More info
NOT ~A More info
XOR xor(A,B) More info

Further reading

I recommend the following books to learn more on logical operations in MATLAB:

  1. MATLAB: A Practical Introduction to Programming and Problem Solving (4th Edition)

    This book was the winner of a 2017 Textbook Excellence Award. Chapters 4 and 5 explain selection statements and loops, two areas that extensively make use of logical operations.

  2. MATLAB for Engineers (5th Edition)

    This excellent book is especially oriented to engineers and scientists who want to learn MATLAB programming. The eighth chapter covers logical operations and selection statements.

Share

Your friends may need this knowledge to complete a task. Share this tutorial.