Essential MATLAB for Engineers and Scientists, Third Edition

Chapter 5: Logical Vectors

Overview

The objectives of this chapter are to enable you to:

  • Understand logical operators more fully.

And to introduce you to:

  • Logical vectors and how to use them effectively in a number of applications.

  • Logical functions.

This chapter introduces a most powerful and elegant feature of MATLAB, viz., the logical vectors. The topic is so useful and, hence, important that it deserves a chapter of its own.

Try these exercises on the command line:

  1. Enter the following statements:

    r = 1;r <= 0.5        % no semicolon

    If you correctly left out the semicolon after the second statement you will have noticed that it returned the value 0.

  2. Now enter the expression r >= 0.5 (again, no semicolon). It should return the value 1. Note that we already saw in Chapter 2 that a logical expression in MATLAB involving only scalars returns a value of 0 if it is FALSE, and 1 if it is TRUE.

  3. Enter the following statements:

    r = 1:5;r <= 3

    Now the logical expression r <= 3 (where r is a vector) returns a vector:

    1     1     1     0     0

    Can you see how to interpret this result? For each element of r for which r <= 3 is true, 1 is returned; otherwise 0 is returned. Now enter r == 4. Can you see...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Logic Gates
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.