Read a binary file of format float
显示 更早的评论
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
2015-6-3
编辑:Salaheddin Hosseinzadeh
2015-6-3
0 个投票
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.
James Tursa
2015-6-3
0 个投票
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
2015-6-3
James Tursa
2015-6-3
Do you have the C# code that wrote the file? If so, please post the relevant parts that did the writing.
Alon
2015-6-3
James Tursa
2015-6-3
编辑:James Tursa
2015-6-3
Are the values correct for the elements you did read? If so, are you sure there are 138444 floats in the file? What is the file size? To keep the values read in from fread as single use '*float' instead of 'float'.
James Tursa
2015-6-3
编辑:James Tursa
2015-6-3
"... placed in wrong index ..."
Please elaborate on the above phrase. Do the numbers match exactly but in the wrong index? If so, give an example of the first few numbers on the C# side and their locations on the MATLAB side to detail explicitly what the indexing problem is you are seeing.
Using '*float' vs 'float' should not have changed any of the values, so your last comment doesn't make sense to me.
'float' --> Read the numbers as float and convert to duoble
'*float' --> Read the numbers as float and keep them that way (i.e., single)
Alon
2015-6-3
Alon
2015-6-3
Alon
2015-6-3
类别
在 帮助中心 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

