f



help: problem reading binary files in matlab

Hi all, 

   My aim is to read the contents of the binary file, (change the format ) and plot them. I had a problem in reading the binary files I am using. You can download the files at 
  	
http://www.megaupload.com/?d=8IQQ6MOF

These files are the geographical data which are obtained after running a model. the 1987 files are the original files which came with the model example while 2002 files are the one that I created. 

dimensions of the 2002 files is  89 x 121.

this is what I have done: 

fid=fopen('filename', 'rb', 'ieee-le');
A = fread(fid); 

My " A " matrix shows all zeros (which is actually not). To see the actual floating point value I tried using 'vpa (variable precision arithmetic)' but no use. 
 
X = vpa(A); or X = vpa(A,2);o r X = vpa(A,20); 
all of the above give me the same answer. 

The binary files are generated in Linux Intel FORTRAN compiler, and I am working on Matlab in windows vista. 

Thanks, 
Narendra. 
0
narendra (1)
11/12/2008 8:24:02 PM
comp.soft-sys.matlab 211264 articles. 26 followers. lunamoonmoon (257) is leader. Post Follow

4 Replies
894 Views

Similar Articles

[PageSpeed] 45

Narendra Rongali wrote:
....
> The binary files are generated in Linux Intel FORTRAN compiler, and I
> am working on Matlab in windows vista.


Are these Fortran unformatted files or actually "stream" binary? 
Fortran unformatted files by default contain record markers to support 
record operations whereas C-stream files don't and Matlab expects the 
latter.  While the Intel compiler (and virtually all others as well) 
have extensions that allow them to create binary files, that isn't the 
normal so need to check on that.  I wouldn't expect that problem to 
produce 0.0, though, but it's a potential gotcha'.

The other question is the precision of the numeric values written--is it 
single or double precision?

Unless the files were generated using a non-native format (also a 
Fortran extension but several are supported by the Intel compilers), I 
don't believe there's any need for the 'ieee-le' option, but it 
shouldn't cause a problem.

--
0
none1568 (7453)
11/12/2008 10:38:51 PM
dpb wrote:
....

> The other question is the precision of the numeric values written--is it 
> single or double precision?
....

That you would specify on the fread() call as 'single' or 'double'

What is the size of the file in bytes and how many entries is that 
supposed to be again?  From that can probably infer the answers to the 
question about unformatted vis a vis "binary" i/o and the precision...

--
0
none1568 (7453)
11/13/2008 2:32:17 AM
dpb <none@non.net> wrote in message <gffm5t$14k$1@aioe.org>...
> Narendra Rongali wrote:
> ...
> > The binary files are generated in Linux Intel FORTRAN compiler, and I
> > am working on Matlab in windows vista.
> 
> 
> Are these Fortran unformatted files or actually "stream" binary? 
> Fortran unformatted files by default contain record markers to support 
> record operations whereas C-stream files don't and Matlab expects the 
> latter.  While the Intel compiler (and virtually all others as well) 
> have extensions that allow them to create binary files, that isn't the 
> normal so need to check on that.  I wouldn't expect that problem to 
> produce 0.0, though, but it's a potential gotcha'.
> 
> The other question is the precision of the numeric values written--is it 
> single or double precision?
> 
> Unless the files were generated using a non-native format (also a 
> Fortran extension but several are supported by the Intel compilers), I 
> don't believe there's any need for the 'ieee-le' option, but it 
> shouldn't cause a problem.
> 
> --
..
FYI, the Intel Fortran Compiler on the PC binary unformatted sequential record format is:
..
4-byte integer, number of bytes in record (not including these 4 bytes)
The binary byte data
Repeat the 4-byte integer
..
I have successfully read in this format into MATLAB using fopen and fread.
..
James Tursa
..

0
11/13/2008 5:28:01 AM
"Narendra Rongali" <narendra@gri.msstate.edu> wrote in message <gffe12$nql$1@fred.mathworks.com>...
> Hi all, 
> 
>    My aim is to read the contents of the binary file, (change the format ) and plot them. I had a problem in reading the binary files I am using. You can download the files at 
>   	
> http://www.megaupload.com/?d=8IQQ6MOF
> 
> These files are the geographical data which are obtained after running a model. the 1987 files are the original files which came with the model example while 2002 files are the one that I created. 
> 
> dimensions of the 2002 files is  89 x 121.
> 
> this is what I have done: 
> 
> fid=fopen('filename', 'rb', 'ieee-le');
> A = fread(fid); 
> 
> My " A " matrix shows all zeros (which is actually not). To see the actual floating point value I tried using 'vpa (variable precision arithmetic)' but no use. 
>  
> X = vpa(A); or X = vpa(A,2);o r X = vpa(A,20); 
> all of the above give me the same answer. 
> 
> The binary files are generated in Linux Intel FORTRAN compiler, and I am working on Matlab in windows vista. 
> 
> Thanks, 
> Narendra. 
..
I downloaded your files and examined them in a MATLAB script and in a C program ... the data is in fact zeros. How are you generating this data? Can you post your Fortran code?
..
James Tursa
..

0
11/13/2008 5:57:02 AM
Reply:

Similar Artilces:

load5
As a solution to some posts a while ago about reading compressed matlab 7 files in matlab 6, i posted load5 to the file exchange (7734) which does this. Note that the "Other Requirements" field on the FX is outdated as the zip file has both windows and linux versions and DOES search the matlab path if the file is not found in the current directory. ...

How to read and plot binary file in matlab?
I have binary file created from labview "Analog In" and "write to file" VI's.their are three channels in labview application. In matlab I am trying to read this binary file using "fread" command but I dont know how to separate each channel in matlab fread command and save it to ascii file? saving should be like this . first column sholud be first channel of labview second column should be secong channel of labview and so on any one who can help ? waiting for response thanks Haider ...

how to call matlab file to another matlab file
Hey friends, i am working on simulation of power system using matlab. for that i have written codes for generation side and line side separately. Now i want to use the result of generation file to line file....so how can i use the result of one file to another.... eg i have gen.m file from that i can get hourly gen data....now i want to compare that data to line.....and line modelling is done in separate file line.m so i want to call result of gen.m file to line.m file..... waiting for ur valuable suggestion thanks ...

How to read Labview binary files in Matlab
I have seen this asked on here before, but with no real answers. Assuming you dont have access to labview, is there any way to load labview binary files into Matlab? I have someone sending me files and I understand that you can save them as .MAT from labview, but I dont have that option. Thanks. Matthias Do you have access to Labview, with application builder? In that case make a VI that converts your labview file to MAT. or If use matlabnode in labview. I think can read sgl or dbl files made in Labview in matlab, however if I remember there is some difference in the format. But it is not o...

Read Matlab 7 .mat files in Matlab 6.5 -- SOLUTION
Thank you Dan for the suggestion of topic change (from MAT file format R13 vs R14, Please Read even if you viewed other post). I have submitted a linux x86 version of the load5 to the File Exchange, i guess it will take a couple days to get up there. If you need it sooner, let me know. Also, still looking for the Windows versions of Matlab 6 dll's (libmx.dll, libmex.dll, libmat.dll) plus the .def files and the mexversion so I can compile in Windows. If you have these, please reply so I can set up a way to get them from you. Below is an example using the load5 mex function from linux. ...

load5
After lots of hunting around with old friends, I was able to locate Windows libraries of Matlab 6.5. In addition, I have put a couple "extras" into the load5 command. As soon as it appears in the file exchange (and i notice it), i will update the file to a .zip file which will contain both Windows and Linux versions of load5. Note that if you use this MEX file with R14 in linux, you will need to copy the libz.so.1.2.2 to either the matlab directory and modify the symbolic links libz.so and libz.so.1, or put it in your path and make sure the LD_LIBRARY_PATH has your directory prece...

problems with code to convert ncs file in matlab under Matlab R14(2004)
Hello to everyone, Ill try to run Nlx2MatCSC ( a code from neuralynx than convert continuous file to matlab variables) in Matlab R14 (2004), and it doesn't work: When I type: >> [Timestamp, ChanNum, SampleFrequency, NumValSamples, Samples] = Nlx2MatCSC(Filename, [1 1 1 1 1], 0, 3, [0 4 9]); ??? Attempt to execute SCRIPT Nlx2MatCSC as a function. I heard that this code is running in Matlab 2007a and newer, but...what about this old version? Any help, Cheers ...

How to read a binary file saved in C++ into Matlab
I created a binary file ( myBinary.bin) saved in C++, and I want to read this data file into Matlab for graphical purposes. The "myBinary.bin" file contains the header class and the myArray[200][300]. Here is a source code in C++: ofstream myBinaryFile("myBinary.bin", ios::bianry); myBinaryFile.write( reinterpret_cast <const char*> (&Header), sizeof(Header)); myBinaryFile.write( reinterpret_cast <cost char*> (myArray), sizeof(myArray)); The length of the Header class = 500. The Header class defines in int, double, and char. Please help me out to read thi...

Loading/read problems with tsv files in Matlab
I am trying to load files with file extension .tsv I used a activex control in my guide, and added a functionality for double click using a command "uigetfile" to browse the file. I could retrive filename, pathname, filterindex through this command. I am stuck up with loading the file to do my manuplations, any suggestion would be helpful. My tsv file contains like 30 columns and huge number of rows, example mon tue wed thu ... 100 200 300 400.. .... I need to read the first line of the matrix in text. I tried to use with textread function , but i get error...

Labview binary file format, reading in matlab
Hi, &nbsp; I have some binary files that I wrote in Labview containing data of type double.&nbsp; I'm trying to load the data in Matlab but I am not having much success.&nbsp; In Matlab I am using the fread command and specifying the type as double with the machine format as 'b' for big-endian.&nbsp; But the values I get do not make any sense.&nbsp; Does anyone know what format Labview saves the data in?&nbsp; Is it big-endian?&nbsp; Or something else? &nbsp; Thanks, Todd ...

Read LabView binary file timestamp into Matlab
In case it is useful to someone: If you need to read a LabView binary data file into Matlab, it is tricky to read in the time data because of the way that LabView writes its timestamp into the binary file. Note that the LabView time convention is miliseconds since Jan 1 1904. Here is one approach (may contain errors but will point you in the right direction), %% Read in date information [ fid, msg ] = fopen(FileName, 'r') ; NColumns = 60 ; % Number of data columns - probably different for your dataset! [a, count] = fread(fid, [ NColumns Inf], '*single') ; % Force ...

Hi need help in reading file in matlab
Hi I have a text file . I need to read it to matlab without the headerlines. Is there anyway other than text read. My file is with .s6p file. It consists of 6-port s-parameters. Can anyone help with this. Thanks Madhu wrote: <Summary: The OP has a text file he/she wants to read in, omitting the headerlines. The OP doesn't want to or can't use textread.> I guess my first question is, why do you not want to use textread? (And I don't know about other people, but I have no clue what the file format of a .s6p file is. I don't even know if it's binary or ASCII da...

Reading Labview binary file using Matlab
I need to know how I can read a Labview log file(binary format) using matlab. I tried using fread using the 'ieee-be' option. But so far I have been unsuccessful in reading it correctly. I can read but I am reading a set of bizzare numbers. And I know the log file has both multi channeled time series data (with a timestamp) and some acquisition related information. Please help. Rajesh Is your data stored in their TDMS data format? -Rob Mr. Rob I appreciate your time to help me with my problem. I dont know what is TDMS format. Is there any easy way I can find that out. Th...

problem with matlab compile error in matlab6.5 work in matlab 7, help!
hi to all, i have a problem running this code on Matlab 6.5, it running fine on matlab Version 7.1.0.183 (R14) Service Pack 3 (but i have not this version) Matlab 6.5 give me a compilation error: ?? Error: File: C:\Documents and Settings\Roby\Documenti\Tesi\portoni_sd_sa\portoni_sd_sa\portoni_2d.m Line: 23 Column: 19 "identifier" expected, "(" found. row 23 col 19 start from @(points) ... (at line begining with error_function = ) Can u help me to resolve this error? can u give me sugestion how can write this line i'm a beginner and i can't understand why t...

Web resources about - help: problem reading binary files in matlab - comp.soft-sys.matlab

Is–ought problem - Wikipedia, the free encyclopedia
The is–ought problem in meta-ethics as articulated by Scottish philosopher and historian David Hume (1711–76) is that many writers make claims ...

GST increase does not tackle the fundamental problem
Victorian Treasurer Tim Pallas has a point. If we are going to &quot;reform&quot; the tax system let's be very clear about what we are trying ...

"The Yale Problem"
... nice woman who was trying to help them, and reducing her to tears. As we’ve seen more and more of this, I’ve begun calling it, “the Yale problem,” ...

January 2016: New Year, Old Problems Edition
... Drop in Nissan Leaf, Toyota Prius demand more than offset gains from Tesla, Chevy Volt Continue reading January 2016: New Year, Old Problems ...

Will the Galaxy S7 have a ‘chipgate’ problem of its own?
Soon after the iPhone 6s became available to buyers last September, some users starting probing the two chip models powering iPhone 6s models. ...

Weekend Reading: Cosma Shalizi (2012): In Soviet Union, Optimization Problem Solves You
In Soviet Union, Optimization Problem Solves You: Attention conservation notice: Over 7800 words about optimal planning for a socialist economy ...

The technology behind bitcoin could solve a big problem banks had in the 2008 crisis
... blockchain than just budgetary hype. Not only does the technology have the potential to cut costs, it could also solve one of the biggest problems ...

Air bag problem: Automakers to recall 5M vehicles
Continental Automotive Systems says moisture can get inside its air bag control computers, causing power supplies to corrode and fail

The Grinder Is Having Some Problems, Here's What We Know
Fox is a network that is often known for comedy, and this year the little network that could has released a few brand new comedies in order to ...

Cash is king, and that's a big problem
Financial advisor Mitch Goldberg sees a big problem: too much cash, and too few good bets in the stock market.

Resources last updated: 2/5/2016 4:52:05 PM