Skip to Main Content Skip to Search
Product Documentation

Handling Data Conversion Between Java and MATLAB

Overview

The call signature for a method that encapsulates a MATLAB function uses one of the MATLAB data conversion classes to pass arguments and return output. When you call any such method, all input arguments not derived from one of the MWArray classes are converted by the builder to the correct MWArray type before being passed to the MATLAB method.

For example, consider the following Java statement:

result = theFourier.plotfft(3, data, new Double(interval));

The third argument is of type java.lang.Double, which converts to a MATLAB 1-by-1 double array.

Calling MWArray Methods

The conversion rules apply not only when calling your own methods, but also when calling constructors and factory methods belonging to the MWArray classes. For example, the following code calls the constructor for the MWNumericArray class with a Java double input. The MATLAB Builder JA product converts the Java double input to an instance of MWNumericArray having a ClassID property of MWClassID.DOUBLE. This is the equivalent of a MATLAB 1-by-1 double array.

double Adata = 24;
MWNumericArray A = new MWnumericArray(Adata);
System.out.println("Array A is of type " + A.classID());

When you run this example, the results are as follows:

Array A is of type double

Specifying the Type

There is an exception: if you supply a specific data type in the same constructor, the MATLAB Builder JA product converts to that type rather than following the default conversion rules. Here, the code specifies that A should be constructed as a MATLAB 1-by-1 16-bit integer array:

double Adata = 24;
MWNumericArray A = new MWnumericArray(Adata, MWClassID.INT16);
System.out.println("Array A is of type " + A.classID());

When you run this example, the results are as follows:

Array A is of type int16

Creating Buffered Images from a MATLAB Array

Use the renderArrayData method to:

  


Recommended Products

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

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