Chapter 10

Adding Structure to Your Scripts

In This Chapter

arrow Adding decision-making to your scripts

arrow Using recursive functions

arrow Repeating tasks

arrow Defining menus

The scripts and functions you have created so far have all performed a series of tasks, in order, one at a time. However, sometimes it’s important to skip steps or to perform the same step more than once. Humans make decisions about what to do and how often to do it with ease, but computers need a little help. You must provide specific instructions as to when a decision is required and when to do something more than once.

As part of discovering how decisions are made and just how repetition works, you see two practical examples of how to employ your new skills. The first is a technique called recursion, which is simply a method of performing a task more than once, but in an elegant way. Using recursion makes solving some math problems significantly easier. The second involves the use of a menu. Most multifunction applications rely on menus to allow a user to select one option out of a number of possibilities.

Making Decisions ...

Get MATLAB For Dummies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.