【问题标题】:ISO-8859-1 encoding MATLABISO-8859-1 编码 MATLAB
【发布时间】:2013-05-30 15:34:25
【问题描述】:

我在 MATLAB 中遇到 ISO 编码问题。

我有一个日志文件,0..255 之间的所有可能值都以二进制格式存储。 当我在 matlab 中打开此文件并读取一行时,MATLAB 向我显示了 ISO-8859-1 中的正确表示。到目前为止,一切顺利。

例如,值 155 (0x9B) 显示字符“>”。 (任何像这样的小字符值都有效)。 Matlab 正确显示了这一点,但是当我想用double(>) 处理整数值时,返回值是 8250,这不是 ASCII 值。

我可以对文件的编码进行哪些更改?

编辑:日志文件是用 python 编写的,以防万一。

【问题讨论】:

  • 为什么这个标签是python
  • 这和python有什么关系? :D
  • double(ISO-Character) 很抱歉,这只是一个代表......也许double('>') 更好

标签: matlab iso-8859-1


【解决方案1】:

我发现了问题。我错过了在 fopen 命令中设置编码。工作解决方案:

%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);

【讨论】:

    猜你喜欢
    • 2011-12-27
    • 1970-01-01
    • 1970-01-01
    • 2011-02-12
    • 2018-02-21
    • 2012-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多