Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading data from Matlab into Java

Tags:

java

matlab

I'm trying to read a matrix produced in Matlab into a 2D array in java. I've been using jmatio so far for writing from java to a .mat file (successfully), but now can't manage to go the other way around. I've managed to import a matrix into an MLArray object using this code:

matfilereader = new MatFileReader("filename.mat");
MLArray j = matfilereader.getMLArray("dataname");

But other than getting its string representation I couldn't manage to access the data itself. I found no example for this or documentation on the library itself, and I actually wrote a function to parse the intire string into a double[][] array but that's only good if the matrix is smaller than 1000 items...

Would be grateful for any experience or tips, thanks,

Amir

like image 233
Amir Avatar asked Mar 16 '12 04:03

Amir


1 Answers

matfilereader.getMLArray has several subclasses to access different kinds of data in MLArray object.

To represent double array you can cast MLArray to MLDouble:

MLDouble j = (MLDouble)matfilereader.getMLArray("dataname");
like image 77
yuk Avatar answered Oct 07 '22 15:10

yuk