Main Content

Rules for Data Conversion Between Java and MATLAB

Java to MATLAB Conversion

The following table lists the data conversion rules for converting Java® data types to MATLAB® types.

Note

The conversion rules apply to scalars, vectors, matrices, and multidimensional arrays of the types listed.

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

When calling an MWArray class method constructor, supplying a specific data type causes the compiler to convert to that type instead of the default.

Java to MATLAB Conversion Rules

Java TypeMATLAB Type

double

double

float

single

byte

int8

int

int32

short

int16

long

int64

char

char

boolean

logical

java.lang.Double

double

java.lang.Float

single

java.lang.Byte

int8

java.lang.Integer

int32

java.lang.Long

int64

java.lang.Short

int16

java.lang.Number

double

Note

Subclasses of java.lang.Number not listed above are converted to double.

java.lang.Boolean

logical

java.lang.Character

char

java.lang.String

char

Note

A Java string is converted to a 1-by-N array of char with N equal to the length of the input string.

An array of Java strings (String[]) is converted to an M-by-N array of char, with M equal to the number of elements in the input array and N equal to the maximum length of any of the strings in the array.

Higher dimensional arrays of String are converted similarly.

In general, an N-dimensional array of String is converted to an N+1 dimensional array of char with appropriate zero padding where supplied strings have different lengths.

MATLAB to Java Conversion

The following table lists the data conversion rules for converting MATLAB data types to Java types.

Note

The conversion rules apply to scalars, vectors, matrices, and multidimensional arrays of the types listed.

MATLAB to Java Conversion Rules

MATLAB TypeJava Type (Primitive)Java Type (Object)
cellNot applicable

Object

Note

Cell arrays are constructed and accessed as arrays of MWArray.

structureNot applicable

Object

Note

Structure arrays are constructed and accessed as arrays of MWArray.

charcharjava.lang.Character
doubledoublejava.lang.Double
singlefloatjava.lang.Float
int8bytejava.lang.Byte
int16short

java.lang.Short

int32intjava.lang.Integer
int64longjava.lang.Long
uint8byte

java.lang.Byte

Java has no unsigned type to represent the uint8 used in MATLAB. Construction of and access to MATLAB arrays of an unsigned type requires conversion.

uint16

short

java.lang.short

Java has no unsigned type to represent the uint16 used in MATLAB. Construction of and access to MATLAB arrays of an unsigned type requires conversion.

uint32int

java.lang.Integer

Java has no unsigned type to represent the uint32 used in MATLAB. Construction of and access to MATLAB arrays of an unsigned type requires conversion.

uint64long

java.lang.Long

Java has no unsigned type to represent the uint64 used in MATLAB. Construction of and access to MATLAB arrays of an unsigned type requires conversion.

logicalbooleanjava.lang.Boolean
Function handleNot supported
Java classNot supported
User classNot supported

Unsupported MATLAB Array Types

Java has no unsigned types to represent the uint8, uint16, uint32, and uint64 types used in MATLAB. Construction of and access to MATLAB arrays of an unsigned type requires conversion.