2013-05-30 37 views
-1

我在MATLAB中使用ISO編碼時遇到問題。ISO-8859-1編碼MATLAB

我有一個日誌文件,所有可能的值在0..255之間以二進制格式存儲。 當我在matlab中打開這個文件並閱讀一行時,MATLAB向我展示了ISO-8859-1中的正確表示。到現在爲止還挺好。

例如值155(0x9B)顯示字符「>」。 (任何小字符值都像這樣的作品)。 Matlab正確顯示了這一點,但是當我想用double(>)處理整數值時,返回值是8250,它不是ASCII值。

我可以在文件的編碼中改變什麼?

編輯:日誌文件是用python編寫的,以防萬一。

+2

爲什麼標記爲「python」? – mgilson

+1

這與python有什麼關係? :D –

+0

'double(ISO-Character)'對不起,這只是一個表示......也許'double('>')'更好 –

回答

0

我找到了問題。我錯過了在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);