Reading data from Matlab in Java

I am trying to read a matrix created in Matlab into a 2D array in java. I have used jmatio so far to write from java to a .mat file (successfully), but now I can’t switch to another vice versa. I managed to import the matrix into an MLArray object using this code:

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

But apart from getting a string representation, I was unable to access the data itself. I did not find an example for this or documentation on the library itself, and I actually wrote a function for parsing an int string into a double [] [] array, but this is only useful if the matrix is ​​less than 1000 elements ...

I would be grateful for any experience or advice, thanks,

Amir

+6
source share
2 answers

matfilereader.getMLArray has several subclasses for accessing various data types in an MLArray object.

To represent a double array, you can use MLArray for MLDouble:

 MLDouble j = (MLDouble)matfilereader.getMLArray("dataname"); 
+2
source

I am not familiar with this tool, but it is quite old. Try saving an older version of the *.mat file and see if your results have changed. That is, add the flag '-v7.0' or '-v6' when you save the r * .mat file.

Code example:

 save filename var1 var2 -v7.0 

or

 save filename var1 var2 -v6 
0
source

Source: https://habr.com/ru/post/910871/


All Articles