从matlab中读取平面文件

本文关键字:平面文件 读取 matlab | 更新日期: 2023-09-27 18:11:37

我想通过matlab读取包含二进制数据的平面文件…我该怎么做呢?数据实际上是以二进制形式保存在。dat文件

中的双精度数字

谢谢

从matlab中读取平面文件

有很多方法可以做到这一点,我通常使用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

使用FileStream打开该文件,然后将其包装到BinaryReader中。它给你ReadDouble, ReadByte等方法