Professional Documents
Culture Documents
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.
All the arithmetic operators have higher precedence than all relational operators.
Relational operators work on arrays too. Even one of the operands can be a scalar too, which is a special
case.
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.
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.