MATLAB reading a mixed data type binary file

故事扮演 提交于 2019-12-04 06:29:41

问题


I am having trouble reading a very large binary file (1,000,000 bytes +)

If I fread the file in a 1 byte data format for example 'uint8' the number of data read equals the size of the file so memory isn't an issue.

I know in this binary file there is data of type 'int16' and 'single' however I don't know the structure of the file. I think the file is structured so there is an 'int16' data point followed by a 'single' data point and this is repeated until the end of the file.

I do not know how to do this reading of mixed data types.

I think I need a loop of some sort?

Thanks in advance for any help or suggestions given


回答1:


using the skip property allows to read the single and uint16 in one step each

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

Not tested Sample Code:

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


来源:https://stackoverflow.com/questions/32457759/matlab-reading-a-mixed-data-type-binary-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!