This example shows you how to use a delegate in MATLAB®. It creates a delegate using a MATLAB function (char
).
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 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, has a signature that matches the delInteger
delegate. For example, the following command displays the !
character:
char(33)
To create an instance of the delInteger
delegate, pass the
function handle of the char
function:
myFunction = NetDocDelegate.delInteger(@char);
Use myFunction
the same as you would char
.
For example, the following command displays the !
character:
myFunction(33)