23.12.2012 Views

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

else<br />

2else<br />

Purpose Conditionally execute statements<br />

Syntax if expression<br />

statements1<br />

else<br />

statements2<br />

end<br />

Description else is used to delineate an alternate block of statements. If expression<br />

evaluates as false, <strong>MATLAB</strong> executes the one or more commands denoted<br />

here as statements2.<br />

2-486<br />

A true expression has either a logical true or nonzero value. For nonscalar<br />

expressions, (for example, “if (matrix A is less than matrix B)”), true means<br />

that every element of the resulting matrix has a logical true or nonzero value.<br />

Expressions usually involve relational operations such as (count < limit) or<br />

isreal(A). Simple expressions can be combined by logical operators (&,|,~) into<br />

compound expressions such as: (count < limit) & ((height - offset) >=<br />

0).<br />

See if for more information.<br />

Examples In this example, if both of the conditions are not satisfied, then the student fails<br />

the course.<br />

if ((attendance >= 0.90) & (grade_average >= 60))<br />

pass = 1;<br />

else<br />

fail = 1;<br />

end;<br />

See Also if, elseif, end, for, while, switch, break, return, relational_operators,<br />

logical_operators

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

Saved successfully!

Ooh no, something went wrong!