Programming and Data Types    

A Simple Function Handle

The repmat function is an elementary matrix function, which is defined in MATLAB with the single M-file, repmat.m. If you create a function handle to the repmat function, MATLAB stores in the handle the information it will need later to evaluate the function. Included in this information is the repmat.m source file path, toolbox\matlab\elmat\repmat.m.

Once you create a function handle, it is not affected by certain changes you might make in your MATLAB environment. For example, if you construct a handle to the repmat function and, later, write additional repmat.m methods to overload the function, the handle still sees only the original function. Also, if you remove the path to repmat.m from the search path, MATLAB is still able to locate and evaluate the function using the handle that you created prior to the path change.

Since repmat is not an overloaded function in this case, evaluation of the function through its handle is fairly simple. You call feval on the function handle, also passing any arguments the function should act upon. MATLAB executes the one function whose access information is stored in the handle.


  Overview Constructing a Function Handle