user1193134
user1193134

Reputation: 163

export Java object and import it into matlab


I try to get large arrays from java into matlab. My problem ist, the java program is to large to run java in matlab, so I need to export the data from java and load it into matlab. Do anyone tried this?

This is how far I got: I've wrote a class containing all values that should be exported

------- Export.java -------
import java.io.Serializable;
public class Export implements Serializable {
private double[][] values;
private String description;
public Export(String description,double[][] values){
    this.description=description;
    this.values=values;
}
public String getDescription(){return description;}
public double[][] getValues(){return values;}
}
--------------------------

And an main methode

------- StartPoint.java -------
public class StartPoint {
public static void main(String[] args) {
    Export serial= new Export("description",new double[][]{{1,2},{3,4}});
      OutputStream file;
    try {
        file = new FileOutputStream( "object.ser" );
        OutputStream buffer = new BufferedOutputStream( file );
        ObjectOutput output = new ObjectOutputStream( buffer );
        output.writeObject(serial);
        output.close();
    } 
    catch (FileNotFoundException e) {e.printStackTrace();}
    catch (IOException e) {e.printStackTrace();}
    System.out.println("done");
    }
}
--------------------------

Accroding to http://www.weizmann.ac.il/matlab/techdoc/matlab_external/ch_java9.html the matlab-code should be easy, but I don't get ist. So any help for the matlab code would be great.

Thanks

Upvotes: 1

Views: 787

Answers (1)

Klas Lindbäck
Klas Lindbäck

Reputation: 33273

To facilitate the import in Matlab I suggest that you write the data using the MAT-file format. Then you will be able to load the files into Matlab variables.

Upvotes: 1

Related Questions