📄 read_float32_hex.m
字号:
function A=read_float32_hex(name)
%
% A = read_float32_hex(filename)
%
% Read the single precision floating-point values
% stored in a Code Composer Studio .dat file.
%
% Return value: A = vector containing elements from .dat file
fid = fopen(name,'rt');
x = fscanf(fid,'%d',2);
if x(1) ~= 1651 | x(2) ~= 1
error('Not a valid hex-format .dat file!')
end
% there is no way to directly convert a string of hex-coded
% bits into the corresponding floating point value
% we have to trick matlab by writing to an intermediate binary
% file
x = fscanf(fid,'%s',3);
x = fscanf(fid,'%c',1);
x = fscanf(fid,'%c');
x = reshape(x,[11 length(x)/11]);
x = x(3:end-1,:);
x = reshape(x,[2 length(x(:))/2]).';
x = hex2dec(x);
% the byte order in x is big endian
fid2 = fopen('tmp_rw_file','w+','ieee-be');
fwrite(fid2,x,'uint8');
frewind(fid2);
A = fread(fid2,'float32');
fclose(fid);
fclose(fid2);
delete('tmp_rw_file')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -