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.

2elseif<br />

Purpose Conditionally execute statements<br />

Syntax if expression1<br />

statements1<br />

elseif expression2<br />

statements2<br />

end<br />

Description If expression1 evaluates as false and expression2 as true, <strong>MATLAB</strong><br />

executes the one or more commands denoted here as statements2.<br />

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

expressions, (for example, is matrix A less then matrix B), true means that<br />

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 />

Remarks else if, with a space between the else and the if, differs from elseif, with<br />

no space. The former introduces a new, nested if, which must have a matching<br />

end. The latter is used in a linear sequence of conditional statements with only<br />

one terminating end.<br />

The two segments shown below produce identical results. Exactly one of the<br />

four assignments to x is executed, depending upon the values of the three<br />

logical expressions, A, B, and C.<br />

if A if A<br />

x = a x = a<br />

else elseif B<br />

if B x = b<br />

x = b elseif C<br />

else x = c<br />

if C else<br />

x = c x = d<br />

else end<br />

x = d<br />

elseif<br />

2-487

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

Saved successfully!

Ooh no, something went wrong!