Programming Previous page   Next Page

Arrays of Anonymous Functions

To store multiple anonymous functions in an array, use a cell array. The example shown here stores three simple anonymous functions in cell array A:

Execute the first two functions in the cell array by referring to them with the usual cell array syntax, A{1} and A{2}:

Do the same with the third anonymous function that takes two input arguments:

Space Characters in Anonymous Function Elements

Note that while using space characters in the definition of any function can make your code easier to read, spaces in the body of an anonymous function that is defined in a cell array can sometimes be ambiguous to MATLAB. To ensure accurate interpretation of anonymous functions in cell arrays, you can do any of the following:


Previous page  Anonymous Functions Outputs from Anonymous Functions Next page

© 1994-2005 The MathWorks, Inc.