Overview Using .NET from MATLAB

What Is the Microsoft .NET Framework?

The Microsoft® .NET Framework is an integral Windows® component that provides a large body of precoded solutions to common program requirements, and manages the execution of programs written specifically for the Framework.

MATLAB® supports the .NET Framework on the Windows platform only.

Benefits of the MATLAB .NET Interface

The MATLAB .NET interface enables you to:

  • Create instances of .NET classes.

  • Interact with .NET applications via their class members.

Why Use the MATLAB .NET Interface?

Use the MATLAB .NET interface to take advantage of the capabilities of the Microsoft .NET Framework. For example:

  • You have a professionally developed .NET assembly and want to use it to do certain operations, such as access hardware.

  • You want to leverage the capabilities of programming in .NET (for example, you have existing C# programs).

  • You want to access existing Microsoft-supplied classes for .NET.

The speech synthesizer class, available in .NET Framework Version 3.0 and above, is an example of a ready-to-use feature. Create the following Speak function in MATLAB:

function Speak(text)
speak = System.Speech.Synthesis.SpeechSynthesizer;
speak.Volume = 100;

For an example rendering text to speech, type:

Speak('You can use .NET Libraries in MATLAB')

Limitations to .NET Support

MATLAB supports the .NET features C# supports, except for the limits noted in the following table.

Features Not Supported in MATLAB
Cannot use ClassName.propertyname syntax to set static properties. Use NET.setStaticProperty instead.
Unloading an assembly
Passing a structure array, sparse array, or complex number to a .NET property or method
Subclassing .NET classes from MATLAB
Accessing nonpublic class members
Displaying generic methods using methods or methodsview functions. For a workaround, see Display .NET Generic Methods Using Reflection.
Creating an instance of a nested class. For a workaround, see Nested Classes.
Saving (serializing) .NET objects into a MAT-file
Creating .NET arrays with a specific lower bound
Concatenating multiple .NET objects into an array
Implementing interface methods
Hosting .NET controls in figure windows
Casting operations
Calling constructors with ref or out type arguments
Using System.Console.WriteLine to write text to the command window
Pointer type arguments, function pointers, Dllimport keyword
.NET remoting

Using the MATLAB : (colon) operator in a foreach iteration

Adding event listeners to .NET events defined in static classes
Handling .NET events with signatures that do not conform to the standard signature
Creating empty .NET objects
Creating .NET objects that do not belong to a namespace

What's the Difference Between the MATLAB .NET Interface and MATLAB Builder NE?

The MATLAB .NET interface is for MATLAB users who want to use .NET assemblies in MATLAB.

MATLAB Builder™ NE packages MATLAB functions so that .NET programmers can access them. It brings MATLAB into .NET applications. For more information about this product, see Getting Started with MATLAB Builder NE.

System Requirements

The MATLAB interface to .NET is available on the Windows platform only.

You must have the Microsoft .NET Framework installed on your system.

The MATLAB interface requires the .NET Framework Version 4.0 and above. The interface continues to support assemblies built on Framework 2.0 and above. To determine if your system has the supported framework, use the NET.IsNETSupported function.

To use a .NET application, refer to your vendor's product documentation for information about how to install the program and for details about its functionality.

MATLAB Configuration File

MATLAB provides a configuration file, MATLAB.exe.config, in your matlabroot/bin/arch folder. With this file, MATLAB loads the latest core assemblies available on your system. You can modify and use the configuration file at your own risk. For additional information on elements that can be used in the configuration file, please visit the Configuration File Schema for the .NET Framework Web page at http://msdn.microsoft.com/en-us/library/1fk1t1t0.aspx.

Using a .NET assembly in MATLAB

For an example of using .NET in MATLAB, see:

For detailed information, see:

To Learn More About the .NET Framework

For a complete description of the .NET Framework, you need to consult outside resources.

One source of information is the Microsoft Developer Network. Search the .NET Framework Development Center at http://msdn.microsoft.com/en-us/netframework/aa496123 for the term ".NET Framework Class Library". The .NET Framework Class Library is a programming reference manual. Many examples in this documentation refer to classes in this library. There are different versions of the .NET Framework documentation, so be sure to refer to the version that is on your system. See System Requirements for information about version support in MATLAB.

Was this topic helpful?