我想通过matlab阅读包含二进制数据的平面文件, 我怎样才能做到这一点..? 数据实际上是.dat文件中以二进制形式保存的数字
谢谢
答案 0 :(得分:1)
有很多方法可以这样做,我通常使用fread
fileId = fopen('mybinaryfile.dat','r'); %# open the file for reading
myData = fread(fileId,Inf,'double'); %# read everything (Inf) in the file as 'double' values
如果您的数据几乎不适合内存,则可以使用多次读取来访问它
sizeToRead = 10000; %# limit size to 10000 values
fileId = fopen('mybinaryfile.dat','r'); %# open the file for reading
keepGoing=1; %# initialize loop
while(keepGoing)
%# read a maximum of 'sizeToRead' values
myData = fread(fileId,sizeToRead,'double');
%# ...
%# process your data here
%# ...
%# make the loop stop if end of file is reached or error happened
if numel(myData) ~= sizeToRead
keepGoing=0;
end
end
答案 1 :(得分:0)
使用FileStream打开此文件,然后将其包装到BinaryReader中。它为您提供了ReadDouble,ReadByte等方法。