Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Creating primitive arrays using javaArray

2 views
Skip to first unread message

Heeten Choxi

unread,
Nov 16, 2009, 9:22:21 AM11/16/09
to
Is it possible to create a primitive array using javaArray()
I want to create a 2D array of doubles (double[][]) and pass it to a java function, which will modify the values in the array.

When I try:
ja = javaArray('double', 1, 1)

I get:
??? Error using ==> javaArray
No class double can be located on the MATLAB Java classpath

The documentation on javaArray says "You are more likely to use primitive types of double than instances of the java.lang.Double class, but in this context, it affords us a simple example."

However, I can't find an example where a primitive double array gets passed by reference from matlab to java.

Thanks,
Heeten

Ed Yu

unread,
Jan 2, 2010, 9:01:04 PM1/2/10
to
Heeten Choxi,

You are so right, there isn't an easy way to do that... Maybe you can write a java class to do just that:

public class DoubleArray {
public double[][] create(double rows, double cols) {
return new double[rows.intValue()][cols.intValue()];
}
}

Ed.

Heeten Choxi

unread,
Jan 8, 2010, 7:28:02 AM1/8/10
to
Hi Ed,

The problem I'm noticing with that approach is that returning an array from java to matlab seems to be very slow. It's faster to just create a memory mapped file in java and have matlab load the array from that. I was hopinh using javaArray would be faster than both of these approaches and less convoluted then the memory mapped file.

Any ideas on how to get data from java into matlab fast?

0 new messages