Borrar filtros
Borrar filtros

Instead of Hebrew characters I can see only gibberish

18 visualizaciones (últimos 30 días)
Lior
Lior el 3 de Mzo. de 2015
Comentada: Walter Roberson el 15 de Sept. de 2018
Hi,
Iv'e written a Matlab code (using PsychToolbox) that includes printing hebrew characters on the screen. If I run the code on my PC it works fine, I can see the hebrew characters in the right way. But if I run the code on a different PC the characters are printed as gibberish and I cant understand why and how to fix it.
Any suggestions?
Thank in advance, Lior.

Respuestas (1)

Afiq Azaibi
Afiq Azaibi el 2 de Oct. de 2017
MATLAB writes its .m files in ASCII encoding, meaning that any non-ASCII encoded characters are replaced with the character '?'. Though MATLAB can display characters in other encodings in the Editor or Command line, it will write them as ASCII if a user saves the m file using the MATLAB editor.
A workaround to this is for the user to write this to an MLX file instead. If you create a file with just the following:
disp('קק')
Saving it to an M file and reopening will have the characters appear as a question marks. Saving this as an MLX will retain the characters upon reopening.
  3 comentarios
Dvir Haberman
Dvir Haberman el 12 de Sept. de 2018
I'm having a similar problem which I posted here but after more testing it seems to be more foundmental. I saved a file called SourceFile.m containing some hebrew characters: גגעע
Then I ran this code:
fid=fopen('SourceFile.m','r');
line=fgetl(fid);
fclose(fid);
fid=fopen('DestFile.m','w','n','ISO-8859-8');
fwrite(fid,line);
fclose(fid);
I opened DestFile.m and it contained █ (only empty), but the 'line' varaible contains גגעע and when I go and open SourceFile.m I can see גגעע just fine. Font is David btw.
I chose ISO-8859-8 because I saw it should supports hebrew.
Walter Roberson
Walter Roberson el 15 de Sept. de 2018
When you say you opened DestFile.m are you referring to in the MATLAB editor?
When the locale is not set to one of the ones associated with China, Japan, or Korea, then the default in MATLAB is to assume that source files are IOS-8859-1 or Windows-1252 -- or at least that the source files are single byte characters. Your file would not have been able to represent גגעע without using UTF-8 or UTF-16LE or UTF-16BE . MATLAB would display the UTF-16 as... ummmm, my browser crashes when I try to paste the characters here. Blanks and the x multiplication symbols and cent signs.
When you do the fopen to read the file, you should specify the encoding you expect, such as
fid=fopen('SourceFile.m', 'r', 'n', 'UTF16BE');
Then you should not use fgetl(): instead you should use
line = fread(fid, '*uint8');
To do the writing, you should use
translated_line = unicode2native(line, 'ISO-8859-8');
and fwrite() the translated_line

Iniciar sesión para comentar.

Categorías

Más información sobre Timing and presenting 2D and 3D stimuli en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by