This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Call .NET Delegates in MATLAB

This example shows you how to use a delegate in MATLAB®. It creates a delegate using a MATLAB function (char).

Declare a Delegate in a C# Assembly

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.

Load the Assembly Containing the Delegate into MATLAB

If the NetDocDelegate assembly is in your c:\work folder, load the file with the command:

dllPath = fullfile('c:','work','NetDocDelegate.dll');

Select a MATLAB Function

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:


Create an Instance of the Delegate in MATLAB

To create an instance of the delInteger delegate, pass the function handle of the char function:

myFunction = NetDocDelegate.delInteger(@char);

Invoke the Delegate Instance in MATLAB

Use myFunction the same as you would char. For example, the following command displays the ! character:


See Also

Related Examples

More About