2 Replies Latest reply on Mar 6, 2014 12:02 PM by jwenting

    I have a .bin file created in MATLAB and, 400x500 dimensions of a floating number matrix inside this file. I want to transfere the values of this matrix into a float Array or an Arraylist in Java.


      The problem is, the values are completely different than they are saved in MATLAB, and probably I need to shift the values after transforming them into byte arrays.

      I am looking for any of a solution.

      My Java code which reads values of floating numbers from a MATLAB bin file as follows:



      import java.io.*;

      import java.io.File;

      import javax.imageio.ImageIO;

      import java.nio.ByteBuffer; // may be useful?



      public class floatingNumberMatrixReader {

            public static void main(String[] args) throws IOException{

            DataInputStream data_in = new DataInputStream(new BufferedInputStream(new FileInputStream(new File("matlabFile.bin"))));

            float[][] t = new float[400][500];  //  A 2D array (or matrix) for floating numbers to be read.

            int y=0;  // initiation for the second dimension of the matrix


                 for (int x = 0;x<400;x++){

                    //  x is the first dimension of the matrix


                           t[x][y] = data_in.readFloat(); // Reading process

                           System.out.println(t[x][y]);   // Printing process. The values of the numbers are about -7.1090133E34, 2.3835522E-26, and......

                                                                    // They have to be in the range of 10^-6 and 10^6

                                                                    // They are Wrong! and Why?



                     catch (java.io.EOFException eof) {




                     if (x == 399) {

                             x = 0;


                     }  // New row initiation of X-axis



                          System.out.println("File is read completely!");


                     }  // Finish after the last element of the array is filled.