O'Reilly logo

Learning to Program with MATLAB: Building GUI Tools by Craig S. Lent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

images

7.1   MATLAB function files

7.2   Function inputs and outputs

7.3   Local workspaces

7.4   Multiple outputs

7.5   Function files

7.6   Other functional forms

A mathematical function, like y = sin(x), can be thought of as a machine that takes a numerical value x as an input and returns a numerical value y as an output. The precise algorithm it employs to calculate the value is out-of-sight. MATLAB functions can be thought of in analogy with built-in mathematical functions like sine and cosine, but in fact, MATLAB functions operate more generally and play a much greater role. In computer programming, functions are the principal tools for managing complexity. They allow a complicated program to be broken up into many simpler parts, parts that are easier to understand, easier to write, and easier to test.

Functions can have inputs and outputs. Inputs are the values of variables that are sent to the function. There can be several inputs and they can be of any MATLAB class—real numbers, vectors, matrices, arrays, strings, and more. Functions can even take other functions as inputs (such a function is called a function function). Similarly, the output of the function can be any number of values of any class.

In addition to calculating the outputs based on the inputs, a function can have side-effects, that is, it can make something happen beyond assigning values to its outputs. We have ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required