Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB Builder JA   

About the MATLAB Builder JA API

Understanding the MATLAB Builder JA API Data Conversion Classes

When writing your Java application, you can represent your data using objects of any of the data conversion classes. Alternatively, you can use standard Java data types and objects.

The data conversion classes are built as a class hierarchy that represents the major MATLAB array types.

Overview of Classes and Methods in the Data Conversion Class Hierarchy

The root of the data conversion class hierarchy is the MWArray abstract class. The MWArray class has the following subclasses representing the major MATLAB types: MWNumericArray, MWLogicalArray, MWCharArray, MWCellArray, and MWStructArray.

Each subclass stores a reference to a native MATLAB array of that type. Each class provides constructors and a basic set of methods for accessing the underlying array's properties and data. To be specific, MWArray and the classes derived from MWArray provide the following:

Advantage of Using Data Conversion Classes

The MWArray data conversion classes let you pass native type parameters directly without using explicit data conversion. If you pass the same array frequently, you might improve the performance of your program by storing the array in an instance of one of the MWArray subclasses.

Automatic Conversion to MATLAB Types

When you pass an MWArray instance as an input argument, the encapsulated MATLAB array is passed directly to the method being called.

In contrast, if your code uses a native Java primitive or array as an input parameter, the builder converts it to an instance of the appropriate MWArray class before it is passed to the method. The builder can convert any Java string, numeric type, or any multidimensional array of these types to an appropriate MWArray type, using its data conversion rules. See Data Conversion Rules for a list of all the data types that are supported along with their equivalent types in MATLAB.

The conversion rules apply not only when calling your own methods, but also when calling constructors and factory methods belonging to the MWArray classes.

Understanding Function Signatures Generated by the MATLAB Builder JA Product

The Java programming language now supports optional function arguments in the way that MATLAB does with varargin and varargout. To support this feature of MATLAB, the builder generates a single overloaded Java method that accommodates any number of input arguments. This behavior is an enhancement over previous versions of varargin support that only handled a limited number of arguments.

Understanding MATLAB Function Signatures

As background, recall that the generic MATLAB function has the following structure:

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

To the left of the equal sign, the function specifies a set of explicit and optional return arguments.

To the right of the equal sign, the function lists explicit input arguments followed by one or more optional arguments.

Each argument represents a MATLAB type. When you include the varargin or varargout argument, you can specify any number of inputs or outputs beyond the ones that are explicitly declared.

Overloaded Methods in Java That Encapsulate M-Code

When the MATLAB Builder JA product encapsulates your M-code, it creates an overloaded method that implements the MATLAB functions. This overloaded method corresponds to a call to the generic MATLAB function for each combination of the possible number and type of input arguments.

In addition to encapsulating input arguments, the builder creates another method, which represents the output arguments, or return values, of the MATLAB function. This additional overloaded method takes care of return values for the encapsulated MATLAB function. This method of encapsulating the information about return values simulates the mlx interface in the MATLAB Compiler product.

These overloaded methods are called the standard interface (encapsulating input arguments) and the mlx interface (encapsulating return values). See Programming Interfaces Generated by the MATLAB Builder JA Product for details.

Adding Fields to Data Structures and Data Structure Arrays

When adding fields to data structures and data structure arrays, do so using standard programming techniques. Do not use the set command as a shortcut.

For examples of how to correctly add fields to data structures and data structure arrays, see the programming examples in Sample Java Applications.

Returning Data from MATLAB to Java

All data returned from a method coded in MATLAB is passed as an instance of the appropriate MWArray subclass. For example, a MATLAB cell array is returned to the Java application as an MWCellArray object.

Return data is not converted to a Java type. If you choose to use a Java type, you must convert to that type using the toArray method of the MWArray subclass to which the return data belongs.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS