This example shows you how to use a delegate in MATLAB®.
It creates a delegate using a MATLAB function (
For another example, see Create Delegates from .NET Object Methods.
This example consists of the following tasks:
The C# example
NetDocDelegate.cs, in the
defines delegates used in the following examples. To see the code, open
the file in MATLAB Editor. To run the examples, build
NetDocDelegate assembly as described in Build a .NET Application for MATLAB Examples.
NetDocDelegate assembly is in your
load the file with the command:
dllPath = fullfile('c:','work','NetDocDelegate.dll'); NET.addAssembly(dllPath);
delInteger delegate encapsulates any
method that takes an integer input and returns a string. The MATLAB
char function, which converts a nonnegative
integer into a character array (string), has a signature that matches
delInteger delegate. For example, the following
command displays the
To create an instance of the
pass the function handle of the
myFunction = NetDocDelegate.delInteger(@char);
myFunction the same as you would
For example, the following command displays the