15.11.2014 Views

Chapter 4: Programming in Matlab - College of the Redwoods

Chapter 4: Programming in Matlab - College of the Redwoods

Chapter 4: Programming in Matlab - College of the Redwoods

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Section 4.1 Logical Arrays 263<br />

>> A=logical(A)<br />

Warn<strong>in</strong>g: Values o<strong>the</strong>r than 0 or 1 converted to logical 1.<br />

A =<br />

0 1 1<br />

1 0 0<br />

1 1 1<br />

Note that all nonzero entries <strong>in</strong> <strong>the</strong> orig<strong>in</strong>al matrix A are now logical 1, while all<br />

zeros <strong>in</strong> <strong>the</strong> orig<strong>in</strong>al matrix A are now logical zero. You can test <strong>the</strong> new class <strong>of</strong><br />

matrix A with <strong>the</strong> follow<strong>in</strong>g command.<br />

>> class(A)<br />

ans =<br />

logical<br />

Relational Operators<br />

<strong>Matlab</strong> provides a complete list <strong>of</strong> relational operators (see Table 4.1).<br />

Operator<br />

Description<br />

< Less than<br />

≤<br />

Less than or equal to<br />

> Greater than<br />

≥<br />

Greater than or equal to<br />

== Equal to<br />

∼= Not equal to<br />

Table 4.1. <strong>Matlab</strong>’s<br />

relational operators.<br />

The <strong>Matlab</strong> relational operators compare correspond<strong>in</strong>g elements <strong>of</strong> arrays with<br />

equal dimensions. Relational operators always operate element-by-element. That<br />

is, <strong>the</strong>y are “array smart.”<br />

For example, consider <strong>the</strong> vectors v and w.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!