Main Content

Interfaces Generated by MATLAB Compiler SDK

MATLAB® Compiler SDK™ generates one or more APIs for each MATLAB function in the .NET assembly based on the MATLAB function signature.

  • A single output signature that assumes that only a single output is required and returns the result in a single MWArray rather than an array of MWArray.

  • A standard signature that specifies inputs of type MWArray and returns values as an array of MWArray.

  • A feval signature that includes both input and output arguments in the argument list rather than returning outputs as a return value. Output arguments are specified first, followed by the input arguments.

Single Output API

For each MATLAB function in the .NET assembly, MATLAB Compiler SDK generates a wrapper class that has overloaded methods to implement the various forms of the generic MATLAB function call. The single output API for a MATLAB function returns a single MWArray.

Typically, you use the single output interface for MATLAB functions that return a single argument. You can also use the single output interface when you want to use the output of a function as the input to another function.

The following table shows a generic function foo along with the single output API that the compiler generates for its several forms.

Generic MATLAB function
function [Out1, Out2, ..., varargout] = foo(In1, In2, ..., InN, 
varargin)
API if there are no input arguments
public MWArray foo() 
API if there are one or more input arguments
public MWArray foo(MWArray In1, MWArray In2...MWArray inN)
API if there are optional input arguments
public MWArray foo(MWArray In1, MWArray In2,      ..., MWArray 
inN
params MWArray[] varargin)

In the example, the input arguments In1, In2, and inN are of type MWArray.

Similarly, in the case of optional arguments, the params arguments are of type MWArray. (The varargin argument is similar to the varargin function in MATLAB — it allows the user to pass a variable number of arguments.)

Note

When you call a class method in your .NET application, specify all required inputs first, followed by any optional arguments.

Functions having a single integer input require an explicit cast to type MWNumericArray to distinguish the method signature from a standard interface signature that has no input arguments.

Standard API

Typically, you use the standard interface for MATLAB functions that return multiple output values.

The standard calling interface returns an array of MWArray rather than a single array object.

The following table shows the standard API for a generic function with none, one, more than one, or a variable number of arguments.

Generic MATLAB function
function [Out1, Out2, ..., varargout] = foo(In1, In2, ..., InN, 
varargin)
API if there are no input arguments
public MWArray[] foo(int numArgsOut) 
API if there is one input argument
public MWArray [] foo(int numArgsOut, MWArray In1) 
API if there are two to N input arguments
public MWArray[] foo(int numArgsOut, MWArray In1,MWArray In2, 
\... MWArray InN) 
API if there are optional arguments, represented by the varargin argument
public MWArray[] foo(int numArgsOut,MWArray in1,MWArray in2, 
MWArray InN,
params MWArray[] 
varargin)

Details about the arguments for these samples of standard signatures are shown in the following table.

ArgumentDescriptionDetails
numArgsOutNumber of outputs

An integer indicating the number of outputs you want the method to return.

The numArgsOut argument must always be the first argument in the list.

In1, In2, ...InNRequired input arguments

All arguments that follow numArgsOut in the argument list are inputs to the method being called.

Specify all required inputs first. Each required input must be of type MWArray or one of its derived types.

vararginOptional inputs

You can also specify optional inputs if your MATLAB code uses the varargin input: list the optional inputs, or put them in an MWArray[] argument, placing the array last in the argument list.

Out1, Out2, ...OutNOutput arguments

With the standard calling interface, all output arguments are returned as an array of MWArray.

feval API

In addition to the methods in the single API and the standard API, in most cases, the MATLAB Compiler SDK product produces an additional overloaded method. If the original MATLAB code contains no output arguments, then the compiler will not generate the feval method interface.

Consider a function with the following structure:

function [Out1, Out2, ..., varargout] = foo(In1, In2, ..., InN, 
varargin)

The compiler generates the following API, known as the feval interface.

public void foo 
            (int numArgsOut,
             ref MWArray [] ArgsOut, 
             MWArray[] ArgsIn)

The interface accepts the following arguments:

numArgsOutNumber of outputs

An integer indicating the number of outputs you want to return.

This number generally matches the number of output arguments that follow. The varargout array counts as just one argument, if present.

ref MWArray [] ArgsOutOutput arguments

Following numArgsOut are all the outputs of the original MATLAB code, each listed in the same order as they appear on the left side of the original MATLAB code.

A ref attribute prefaces all output arguments, indicating that these arrays are passed by reference.

MWArray[] ArgsInInput arguments

MWArray types or supported .NET primitive types.

When you pass an instance of an MWArray type, the underlying MATLAB array is passed directly to the called function. Native types are first converted to MWArray types.