Thread Subject: Creating primitive arrays using javaArray

Subject: Creating primitive arrays using javaArray

From: Heeten Choxi

Date: 16 Nov, 2009 14:22:21

Message: 1 of 3

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

Subject: Creating primitive arrays using javaArray

From: Ed Yu

Date: 3 Jan, 2010 02:01:04

Message: 2 of 3

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.

Subject: Creating primitive arrays using javaArray

From: Heeten Choxi

Date: 8 Jan, 2010 12:28:02

Message: 3 of 3

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?

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
array Heeten Choxi 8 Jan, 2010 07:29:06
performance Heeten Choxi 8 Jan, 2010 07:29:06
java Heeten Choxi 16 Nov, 2009 09:24:24
rssFeed for this Thread

Contact us at files@mathworks.com