Elements of a .NET Engine Program
MATLAB® engine API for .NET enables .NET programs to interact with MATLAB synchronously or asynchronously. Supported operations include:
Start MATLAB.
Connect to a MATLAB shared session on the local machine.
Call MATLAB functions with input arguments passed from .NET and output variables returned from MATLAB.
Evaluate MATLAB statements in the MATLAB base workspace.
Pass variables from .NET to MATLAB and from MATLAB to .NET.
The size of data arrays passed between .NET and MATLAB is limited to 2 GB. This limit applies to the data plus supporting information passed between the processes.
Coding Environment
MATLAB engine API for .NET consists of these classes and is included in the MATLAB product.
Before using the API, set up your build and run-time environment. For more information, see Requirements to Build .NET Engine Programs.
Coding Patterns
Namespaces
The MathWorks.MATLAB.Engine
namespace contains the MATLAB Engine for .NET.
The MathWorks.MATLAB.Types
namespace contains the MATLAB Data API for .NET.
The MathWorks.MATLAB.Exceptions
namespace contains the exception
classes for the .NET engine.
Start MATLAB Session
You can start a MATLAB session from your .NET program synchronously or asynchronously. Use these
MathWorks.MATLAB.Engine.MATLABEngine
methods to start MATLAB:
StartMATLAB
— Start a MATLAB session synchronously.StartMATLABAsync
— Start a MATLAB session asynchronously.
For examples, see Start MATLAB Session from .NET.
Call MATLAB Function and Return Result
To call a MATLAB function funcname
on a MATLABEngine
object eng
, type:
retVal = eng.funcname(arg1,arg2,...)
For example, to call linspace
on a point interval of –5 to 5,
type:
double[] A = eng.linspace(-5.0,5.0);
For more examples, see Execute MATLAB Functions from .NET.