MATLAB: Does IMPORTDATA read in HEX files incorrectly in MATLAB

asciiheximportdataMATLAB

I have a hex file of the form
0x0C50 0xDA82 0xFFFF 0xF3D2 0x3D60 0x803E
When I try to read this hex data using IMPORTDATA function and convert it to decimal on a Mac, the data values starting with '0xD' are read as '0xE' when converted to decimal.
I use the following commands:
importdata('test.hex')
where test.hex is the file which contains the above hex data. The output of the statement is
3152 60034 65535 62434 15968 32830
but the data should be
3152 55938 65535 62418 15712 32830
In Windows the same data is read as zeros and in UNIX each row of the file is read as a string.

Best Answer

The ability to read ASCII-coded hex using IMPORTDATA is not available in MATLAB. To work around this issue, use FSCANF to read the file.
For example: Assuming fid is the file id having the information.
fid = fopen('test.hex');
a = fscanf(fid,'%x %x %x %x %x %x');
fclose(fid);