Programming and Data Types    

Testing for Data Type

The isa function identifies the data type or class of a MATLAB variable or object. You can see if a variable holds a function handle by using isa with the function_handle tag. The following function tests an argument passed in to see if it is a function handle before attempting to evaluate it.

Testing for Equality

You can use the isequal function to compare two function handles for equality. For example, you want to execute one particular method you have written for an overloaded function. You create a function handle within a confined scope so that it provides access to that method alone. The function shown below, test_myfun, receives this function handle in the first argument, arg1, and evaluates it.

Before evaluating the handle in arg1, test_myfun checks it against another function handle that has a broader definition. This other handle, @myfun, provides access to all methods for the function. If the function handle in arg1 represents more than the one intended method, an error message is displayed and the function is not evaluated.


  Converting Function Names to Function Handles Saving and Loading Function Handles