You are on page 1of 1

Selection

Control Construct: flow of instructions, two types; Sequential and selection.

Redirecting: Slide, Selection aka branching is not a new nor hard concept.

So is nesting, read up to page 20 to get a clear picture of the concept as well as operator precedence.

Relational and Logical Operator

All the arithmetic operators have higher precedence than all relational operators.

Non-zero values are considered true, zero is considered false.

Relational operators work on arrays too. Even one of the operands can be a scalar too, which is a special
case.

Arithmetic and logical operators can be combined.

To add a number b to total if the number is in between 0 and 10, you can use if-else. But to do it in a
single statement: total = total + b*(0<b && b<10)

Elementwise &/| is used for logical operations on vectors or a vector and a scalar.

Variable Number of Function Arguments

Polymorphic functions can be used to save long calculations if user doesn’t ask for them. Using nargin
and nargout to determine how many parameters the user provided and how many results the user
asked for.

Persistent Variables

A persistent variable is a local variable, so it's only visible inside the function which is defined, but its
value persists across function calls. In other words, MATLAB doesn't discard the value of a persistent
variable when the function returns the way it does with a regular local variable. It keeps that value until
the next call.

You might also like