【问题标题】:MATLAB reading a mixed data type binary fileMATLAB 读取混合数据类型二进制文件
【发布时间】:2015-09-08 22:59:39
【问题描述】:

我无法读取一个非常大的二进制文件(1,000,000 字节 +)

如果我fread 文件采用 1 字节数据格式,例如 'uint8',则读取的数据数量等于文件的大小,因此内存不是问题。

我知道在这个二进制文件中有'int16''single' 类型的数据,但是我不知道文件的结构。我认为该文件是结构化的,因此有一个'int16' 数据点,后跟一个'single' 数据点,并且一直重复到文件末尾。

我不知道如何读取混合数据类型。

我想我需要某种循环?

提前感谢您提供的任何帮助或建议

【问题讨论】:

  • 我建议您查看this answer 并使用解决方案#1(=阅读uint8 中的所有内容,然后使用typecast 获取您的int16single)。请注意,其他解决方案也可以使用,第一个是最快且推荐的解决方案。

标签: matlab types binaryfiles binary-data


【解决方案1】:

使用 skip 属性允许在一个步骤中读取 singleuint16

A = fread(fileID,sizeA,precision,skip)

未测试示例代码:

Integer16 = fread(fileID,sizeA,'uint16',8); %read uin16 and skip the siz eof a single
fseek(fileID, 2, 0) % offset the size of a uint16 
Single = fread(fileID,sizeA,'single',2); % read the singles

【讨论】:

  • brrrr!! ...我知道 Matlab 区分大小写,所以 singleSingle 是不同的符号,但在实践中,我会认真避免命名任何变量 Single(或它的任何大小写变体)。这是灾难的秘诀......
猜你喜欢
  • 2019-02-11
  • 1970-01-01
  • 2020-06-09
  • 1970-01-01
  • 2016-03-14
  • 2013-09-09
  • 1970-01-01
  • 2014-07-30
  • 1970-01-01
相关资源
最近更新 更多