0

I am trying to convert a uint16 Matlab matrix (size: 1109-by-1024) into a Java short[][] using the jmatio library. Following is the code:

String name     = "array_re";
String fileName = "microsec.mat";
MatFileReader matfilereader = new MatFileReader( fileName );
short[][] mlArrayShort = ((MLInt16) matfilereader.getMLArray( name  
                          )).getArray();

However, at the third line, I am getting the following error:

"com.jmatio.io.MatlabIOException: Incorrect matlab array class: uint16".

Does anyone know how to resolve this?

horchler
  • 18,384
  • 4
  • 37
  • 73
sto_user
  • 31
  • 1
  • 8
  • 1
    Have you tried to save the MATLAB array as `int16` instead of `uint16`? Java cannot handle unsigned types. –  Feb 15 '16 at 15:57
  • If your data have values greater than `intmax('int16')` need to use `int32` or re-scale your `uint16` data to use the negative range, – horchler Feb 15 '16 at 16:49
  • @CST-Link. Thank you for catching that. – sto_user Feb 17 '16 at 11:32

1 Answers1

0

Thank you so much for your answers. Yes the problem was that Java does not handle unsigned data types. I converted the matrix from Matlab to signedint16 and read it in Java successfully using the same above code.

sto_user
  • 31
  • 1
  • 8