matlab读取binary,在Matlab中通过fread读取多个精度二进制文件 |
您所在的位置:网站首页 › matlab按字节读取bin文件 › matlab读取binary,在Matlab中通过fread读取多个精度二进制文件 |
您可以使用 FREAD函数的“skip”选项以及 FSEEK一次读取一个“列”的记录: %# type and size in byte of the record fields recordType = {'double' 'double' 'int32' 'int8' 'char'}; recordLen = [8 8 4 1 1]; R = cell(1,numel(recordType)); %# read column-by-column fid = fopen('file.bin','rb'); for i=1:numel(recordType) %# seek to the first field of the first record fseek(fid, sum(recordLen(1:i-1)), 'bof'); %# % read column with specified format, skipping required number of bytes R{i} = fread(fid, Inf, ['*' recordType{i}], sum(recordLen)-recordLen(i)); end fclose(fid); 这段代码一般适用于任何二进制记录文件,您只需指定记录字段的数据类型和字节长度即可.结果将在包含列的单元格数组中返回. |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |