我有一个数据文件,它使用 (char(1 byte)、char[n](array of n chars)、word(2 byte unsigned int)、short(2 byte signed int)、dword(4 byte unsigned int)、long (4 字节有符号整数)和浮点数(4 字节实数)),并且应该采用以下格式。我正在使用 fopen、fread 等将数据文件读入 MATLAB,但我得到的值不是我所期望的。
格式:
- char[8] <-- 输出 8 个拼写正确字符串标识符的 ascii 值
- dword <--数据文件的版本,msw-major 版本,lsw-minor 版本(已尝试读取为 1 uint32 和 2 uint16)
- 双字
- 双字
- 双字
- dword <--程序中显示的窗口数
- displayinfo[8] <--包含以下结构的显示窗口参数:(不确定这是什么数据类型)
- 双字
- 双字
- 双字
- 双字
- 双字
- 双字
- 双字
- 双字
- 双字
- 双字
- 双字
- 双字
- dword(显示窗口参数的结尾;有些被指定为必须是 [0,3] 中的数字,并且它们不会像那样出现)
- 字符[16]
- word <-- 应该是收集了年份数据(2013 年),但显示为 0
代码:
fid = fopen('MIC1.001','rb');
fileIdentifier = fread(fid, 8,'char');
dataFileMajorVersion = fread(fid,1,'uint16');
dateFileMinorVersion = fread(fid,1,'uint16');
numModules = fread(fid,1,'uint32');
fread(fid,1,'uint32'); % value not used
numSwipesCollected = fread(fid,1,'uint32');
numWindowDisplays = fread(fid,1,'uint32');
% display info vars:
displayType = [];
moduleNumber = [];
channelNumber = [];
beginningBar = [];
endBar = [];
vertExpFactor = [];
voltageOffset =[];
isGridEnabled = [];
isEngineeringUnitEnabled = [];
colorOfDisplay = [];
multiChannelIndex = [];
numChannelsForMultiChannelDisp = [];
multiChannelDispStyle = [];
% or does it go through loop for all 8 whether or not there are 8 displays??
for i=1:numWindowDisplays
displayType = [fread(fid,1,'uint32'); displayType];
moduleNumber = [fread(fid,1,'uint32'); moduleNumber];
channelNumber = [fread(fid,1,'uint32'); channelNumber];
beginningBar = [fread(fid,1,'uint32'); beginningBar];
endBar = [fread(fid,1,'uint32'); endBar];
vertExpFactor = [fread(fid,1,'uint32'); vertExpFactor];
voltageOffset =[fread(fid,1,'uint32'); voltageOffset];
isGridEnabled = [fread(fid,1,'uint32'); isGridEnabled];
isEngineeringUnitEnabled = [fread(fid,1,'uint32'); isEngineeringUnitEnabled];
colorOfDisplay = [fread(fid,1,'uint32'); colorOfDisplay];
multiChannelIndex = [fread(fid,1,'uint32'); multiChannelIndex];
numChannelsForMultiChannelDisp = [fread(fid,1,'uint32'); numChannelsForMultiChannelDisp];
multiChannelDispStyle = [fread(fid,1,'uint32'); multiChannelDispStyle];
end
fread(fid,1,'uint32'); % value only used internally
fread(fid,16,'char'); % unused parameter for future use
yearOfDataCollection = fread(fid,1,'uint16');