Read a binary file of format float

55 次查看(过去 30 天)
Alon
Alon 2015-6-3
评论: Alon 2015-6-3
Hello, I have a binary file that holds a content of float array that wa written in c#. I want to read it into matlab to view that float array. I think I need to use the next command but it seems to fail:
myfloat=fread(fID,1,'float');

回答(2 个)

Salaheddin Hosseinzadeh
编辑:Salaheddin Hosseinzadeh 2015-6-3
Hi Alon,
As a C# programmer you know that "it fails" is not enough!
BTW, sometime when I want to generate a file specially on drive C, I have to open MATLAB as an administrator! You may wanna to this as well.
  4 个评论
Salaheddin Hosseinzadeh
Dear Alon,
Just answer James questions.
When you open the file using fopen, do you get a valid File ID?
A valid file ID is an integer.
fileID = fopen('myfile.xyz')
Most importantly, pleaseee post the error message
Alon
Alon 2015-6-3
编辑:Alon 2015-6-3
I do it that way:
fid = fopen('myRecordBin.bin', 'r');
fread(fid,inf,'float',4,'l');
fclose(fid);
Now, I can read it and matlab's workspace show 69222 elements and in the vector it shows: 69222x1 double.
But my original float array(and not double) in c# is twice: 138444 elements.

请先登录,再进行评论。


James Tursa
James Tursa 2015-6-3
Did you open the file first to obtain a valid fID? Are you getting an error message? (If so, please post the entire message). Are you getting garbage for myfloat? (Indicating possible endian problem, or maybe header data not accounted for, or data is not really float, etc.)
  10 个评论
Alon
Alon 2015-6-3
I'm sorry it didn't change the values but still they are placed wrong.
Alon
Alon 2015-6-3
Hello! Thanks for you pleasing answers. I got my problem, here we go:
fid = fopen('myRecordBin.bin', 'r');
myarray=fread(fid,inf,'*float',0,'l');
fclose(fid);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by