views:

70

answers:

1

Hi, I've read the post "Read and write from/to a binary file in Matlab" but I still have doubts. I have a binary file of long double values created with fwrite in C and in Matlab I'm using

fid = fopen('vz3.dat', 'r')
mydata = fread(fid, 'double')

where vz3.dat is my file. But I'm getting garbage values in Matlab. According to

[cinfo, maxsize, ordering] = computer

in Matlab, my computer is a little-endian system (byte ordering system). Any suggestions?

By the way, does a binary file necessarily have to end in .bin .I'm using the .dat extension. Is it ok to do so?

Thanks a lot

+2  A: 

To open a file with little endian, use

fid = fopen('vz3.dat','r','l');

It doesn't matter what the file is called, by the way.

Jonas
Thanks. Now it's working. I've used: format long; fid = fopen('vz3.dat', 'r','l'); mydata = fread(fid, 'double'). Please see my other post "Binary files printing and desired precision". It says Matlab can handle double but not long double.
yCalleecharan