I have a problem with ISO encoding in MATLAB.

I have a logging file, with all possible values between 0..255 stored in binary format. When I open this file in matlab and read one line, MATLAB shows me the correct representation in ISO-8859-1. So far, so good.

For example the value 155 (0x9B) shows the character ">". (Any small character values like this work). Matlab shows this correctly, but when I want process an integer value with double(>) the return value is 8250, which is not an ASCII-Value.

What can I change in the encoding of the file?

edit: the logfile was written with python, in case that matters.

有帮助吗?

解决方案

I find the problem. I missed to set the encoding in the fopen command. Working Solution:

%creating testfile
ascii=char([191    210    191    212    191    228   192    215    192    144      198    175   155    236    254    201    10]);  %problem value here the 155
logID=fopen('testdatei.log','w','n','ISO-8859-1');
fwrite(logID,ascii);
fclose(logID);

% wrong filehandling
logID=fopen('testdatei.log');
line=fgetl(logID);
decode=double(line);
disp('wrong encoding')
decode(13)
fclose(logID);

%right filehandling
logID=fopen('testdatei.log','r','n','ISO-8859-1');
line=fgetl(logID);
decode=double(line);
disp('right encoding')
decode(13)
fclose(logID);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top