Results 1 to 7 of 7
 03052014, 05:48 PM #1Member
 Join Date
 Mar 2014
 Posts
 3
 Rep Power
 0
I can't transfer floating number Matrix(400x500) from MATLAB bin file to a Java Array
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
try{
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.3835522E26, and......
// They have to be in the range of 10^6 and 10^6
// They are Wrong! and Why?
}
catch (java.io.EOFException eof) {
break;
}
if (x == 399) {
x = 0;
y++;
} // New row initiation of Xaxis
if(y==499){
System.out.println("File is read completely!");
data_in.close();
} // Finish after the last element of the array is filled.
}
}
}
 03052014, 06:18 PM #2
Re: I can't transfer floating number Matrix(400x500) from MATLAB bin file to a Java A
Please edit your post and wrap your code with code tags:
[code]
YOUR CODE HERE
[/code]
to get highlighting and preserve formatting.
values are completely different than they are saved in MATLAB
In other words the conversion of the numbers is completely wrong.
Can MATLAB write out one or two numbers to a file that could be examined in a hex editor to see their binary values so a java program could be written to convert MATLAB output to valid java numbers.If you don't understand my response, don't ignore it, ask a question.
 03052014, 06:33 PM #3Senior Member
 Join Date
 Jan 2013
 Location
 Northern Virginia, United States
 Posts
 5,655
 Rep Power
 9
Re: I can't transfer floating number Matrix(400x500) from MATLAB bin file to a Java A
I am unfamiliar with MatLab but it took me about 5 minutes to determine there are variety of import/export facilities as well as quite a few supported file types. It even shows how to integrate some capabilities with Java. Did you check out the documentation?
Regards,
JimThe Java^{TM} Tutorials  SSCCE  Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
 03052014, 06:51 PM #4Member
 Join Date
 Mar 2014
 Posts
 3
 Rep Power
 0
Re: I can't transfer floating number Matrix(400x500) from MATLAB bin file to a Java A
Yes, be cause there are websites showing how to pass from a matlab.bin file to read them in Java. Such as float matrix in a matlab.bin file must be saved with 'singe' parameter to be shown in Java as 'float'. So a 2D matrice must be readable with java.
 03052014, 06:59 PM #5Senior Member
 Join Date
 Jan 2013
 Location
 Northern Virginia, United States
 Posts
 5,655
 Rep Power
 9
Re: I can't transfer floating number Matrix(400x500) from MATLAB bin file to a Java A
Well, I suggest you start off small. Go to MatLab and create a small 1 x 2 array of floats and save them. Then you have several options.
1. Do what Norm suggested and analyze the file with a bin hex editor.
2. Create a 1 x 2 array of floats in java (of the same values of course) and use a DataStream
to write them out and compare to the MatLab version.
3. Find another way to write them to a different and perhaps easier to parse/verify file format.
I presume that MatLab is storing this in IEEE 754 format which means it must be read in as a float and not text. And when you analyze it
it won't look anything like a text floating point number.
Regards,
JimThe Java^{TM} Tutorials  SSCCE  Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
 03052014, 07:04 PM #6Member
 Join Date
 Mar 2014
 Posts
 3
 Rep Power
 0
Re: I can't transfer floating number Matrix(400x500) from MATLAB bin file to a Java A
Dear Jim,
I was graduated from Bilkent University at 2013. I am finished with some books and produced considerable projects. The issue we are talking right now is an issue of year 2009 on another forum in the internet and someone tried to clear up but could not finished to give a sense. Do you want me to share the website with you?
The code upside is the most compact form of it with just 2 parameters of a table as X=400 and Y=500. If the object types are incompatible or if you have another solution let me have your kind response.
Yours sincerely,
Sarp
 03052014, 07:09 PM #7Senior Member
 Join Date
 Jan 2013
 Location
 Northern Virginia, United States
 Posts
 5,655
 Rep Power
 9
Re: I can't transfer floating number Matrix(400x500) from MATLAB bin file to a Java A
The Java^{TM} Tutorials  SSCCE  Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
Similar Threads

How to round up floating number properly?
By IndraG in forum New To JavaReplies: 4Last Post: 01192012, 08:57 AM 
Java array matrix problem.. please help!
By Asvin in forum New To JavaReplies: 5Last Post: 04112011, 07:35 PM 
if it is floating point number
By Stephen Douglas in forum New To JavaReplies: 26Last Post: 07062010, 09:17 AM 
How to transfer 1D array in JAVA to 3D array in C
By fishwater00 in forum New To JavaReplies: 0Last Post: 07312009, 06:24 PM 
number of floating point
By mohammad8065 in forum Advanced JavaReplies: 5Last Post: 12282008, 10:41 AM
Bookmarks