The simplest programs consist of a series of commands that are executed in order, one after the other. Because MATLAB has some very powerful commands, such a program can be quite useful. The real power of programming becomes apparent, though, when we can structure a program so that (a) which commands are executed depends on the values currently stored in variables, and (b) some commands can be executed repeatedly. Statements that don’t directly execute an action, but rather control which other commands will be executed, are called “control flow commands.” In MATLAB the
if statement allows conditional execution, and repetitive execution, making “loops,” is accomplished using the
After mastering the material in this chapter you should be able to write programs that:
ifstatement to conditionally execute a block of commands.
switch-casestatement to conditionally execute one of several ...