This example shows you how to use a delegate in MATLAB®. It creates a delegate using a MATLAB function (char). For another example, see Create Delegates from .NET Object Methods.
This example consists of the following tasks:
|On this page…|
The C# example NetDocDelegate.cs, in the matlabroot/extern/examples/NET/NetSample folder, defines delegates used in the following examples. To see the code, open the fileopen the file in MATLAB Editor. To run the examples, build the NetDocDelegate assembly as described in Build a .NET Application for MATLAB Examples.
If the NetDocDelegate assembly is in your c:\work folder, load the file with the command:
dllPath = fullfile('c:','work','NetDocDelegate.dll'); NET.addAssembly(dllPath);
The 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 the delInteger delegate. For example, the following command displays the ! character:
To create an instance of the delInteger delegate, pass the function handle of the char function:
myFunction = NetDocDelegate.delInteger(@char);