Making Decisions and Repeating Calculations
The most straightforward way of writing a program consists of typing
in a sequence of instructions. Sometimes, however, decisions may have
to be made according to certain specified requirements on what formula
to use in the calculations, for instance, or even whether it is
possible to continue for the given data. MATLAB has a selection of
commands that will allow the user to take decisions and transfer the
control to other parts of the program accordingly. Often we also find
that there are instructions we want to repeat a number of
times. Having to write the same instructions over and over while
changing the data becomes very tedious but MATLAB has a very helpful
command for that purpose.
There are three control structures provided by MATLAB to enable this type
of behaviour:
- IF statements
- Program Loops: FOR and WHILE statements
Exercises
There are two exercises associated with this section after reading
about IF statements and Program loops you should try them both.
Exercise 5 and Exercise 6.
Click HERE for next section.