Java – Passing a million numbers from Java to MATLAB?

Passing a million numbers from Java to MATLAB?… here is a solution to the problem.

Passing a million numbers from Java to MATLAB?

I have some code running in 10.919 seconds. Analysis of it shows that 10.182 s was wasted in

opaque.double

Called when I use it

jClass.GetArrays(jArray1,jArray2);

struct.prop1 = double(jArray1);
struct.prop2 = double(jArray1);

What can be done? I have to interact with external APIs using Java.

EDIT: I used the following hack:

struct.prop1 = cell2mat( cell( jArray1) ); 

and down to 1.5s/2.2s

Edit:

Causes Java to return a long comma-separated string representation of an array and then uses

data = strread(char(jString),'%f','delimiter',',' );

Produced almost tolerable performance

Best Solution

The problem is the use of boxed Java primitives – in this case, java.lang.Double.

Simply changing Java’s signature from Double to Double enables Matlab to work seamlessly with arrays without conversion overhead.

Related Problems and Solutions