Displaying (in the prompt) latin characters, such as á, é, í, ó, ú, and ñ, using MATLAB R2010b/R2011a for mac

Hi MATLAB community.
How can we display (in the prompt) latin characters, such as á, é, í, ó, ú, and ñ, using MATLAB R2010b/R2011a for mac (last iteration of Snow Leopard, 10.6.7)?
For example, when trying to run this script on MATLAB for mac
fprintf('Química, Matemáticas, Español.\n')
the prompt throws me
Qu?mica, Matem?ticas, Espa?ol.
which does not contain any of the latin characters I entered on my script, but those question marks as a replacement.
Any help will be greatly appreciated. Thank you.
P.S. 1: I am using an Apple Western Spanish keyboard to enter those latin characters.
P.S. 2: By prompt I am referring to the MATLAB Command Window.

4 comentarios

You can display any non-ASCII characters with "char(x)". For example, if you want to display the character á, you must write the correct number, in this case, char(225). I tried a lot of numbers to know the correct key. Try yourself.
The success of using char(x) depends upon your locale, and upon your MATLAB version, and your font, and your feature('DefaultCharacterSet')
Unfortunately I am not able to test this in Snow Leopard itself. I have virtual machine software that I tried with, but I hit the limitation that Apple's EULA did not permit Snow Leopard itself to be installed as a virtual machine (it did permit Snow Leopard Server to be installed in a virtual machine.) I think we got rid of the last of our Snow Leopard compatible machines here.
The earliest OS-X I could potentially test with is Lion, the release after Snow Leopard... but if I still have Lion install disks around then then are in some closet or other. Mavericks is the earliest I could definitely try with.
Thanks Fernando and Walter for your reply.
It looks like the bug was fixed some time ago. I am running MATLAB R2016b, and now those characters display correctly on the Command Window.

Iniciar sesión para comentar.

 Respuesta aceptada

Maybe I have been missing the embarrassingly obvious:

disp('Química, Matemáticas, Español.')

5 comentarios

Hi Andrew. I solved it! By changing the locale from "Colombia (English)" to "United States", and deleting some preferences files, such as: ~/.matlab and the .plist, everything started to work as expected. Curious.
Curious indeed. What made you think of deleting the preferences files?
By changing only the locale (from "Colombia (English)" to "United States") there was no effect; so I decided to delete some preferences, and boom!, as simple as that, worked!
I wonder if perhaps it was stuck on a particular output font...
Hi Walter, at this point, I think it is tough to know. But most likely you are right.

Iniciar sesión para comentar.

Más respuestas (2)

You could try changing the locale.
EDIT: I found a better solution:
fprintf(native2unicode('Química, Matemáticas, Español.','latin1'))
The output is:
Química, Matemáticas, Español.>>
I looked at this command earlier but didn't use it in the right way. You said you wanted a prompt, so I took out the \n.

20 comentarios

Andrew, thank you very much for the reply. Your solution works just fine, however I would like to keep the operating system in English. Any idea on how to do that? Many thanks in advance.
Hi Andrew. Your second solution is not working for me. Would you tell me what version of MATLAB are you using as well as your operating system?
It's R2010b on Mac OS 10.6.7 (Snow Leopard).
Andrew, by entering:
fprintf(native2unicode('Química, Matemáticas, Español.','latin1'))
I get:
Qu?mica, Matem?ticas, Espa?ol.>>
Note that my operating system is still in English. I did not change the locale when I ran your script...
fprintf(native2unicode('Química, Matemáticas, Español.','latin1'))
Thank you!
No, you shouldn't need to change the locale - mine is American English.
What do you get if you type
unicode2native('Química, Matemáticas, Español.','latin1')
?
Another thought: in the documentation for native2unicode there is a link to other choices of encoding besides latin1. You could try them and see if it makes any difference.
Hi Andrew. This is what I get:
>> unicode2native('Química, Matemáticas, Español.','latin1')
ans =
Columns 1 through 19
81 117 26 109 105 99 97 44 32 77 97 116 101 109 26 116 105 99 97
Columns 20 through 30
115 44 32 69 115 112 97 26 111 108 46
Besides 'latin1', I also tried: 'UTF-8', 'US-ASCII', and 'Shift_JIS'. But I am getting the same result:
Qu?mica, Matem?ticas, Espa?ol.>>
In case you're wondering why I am suggesting this - your problem character is 26. My corresponding character is 273. So I did some reverse engineering to see which encoding gives me 26.
Andrew, thank you very much for your kind of help. By entering:
unicode2native('Química, Matemáicas, Español.','ISO-8859-1')
I get:
81 117 26 109 105 99 97 44 32 77 97 116 101 109 26 105 99 97 115
Columns 20 through 29
44 32 69 115 112 97 26 111 108 46
which seems to be correct when comparing the 26 number with yours.
But, if now I enter:
fprintf(native2unicode('Química, Matemáticas, Español.','ISO-8859-1'))
I get the same result over and over again no matter what alias I choose. I tried most of the alias specified in http://www.iana.org/assignments/character-sets. but none of them seem to work for me. Any insight of what could be the problem?
Thank you.
For example,
unicode2native('Química, Matemáticas, Español.','UTF-8')
ans =
Columns 1 through 19
81 117 26 109 105 99 97 44 32 77 97 116 101 109 26 116 105 99 97
Columns 20 through 30
115 44 32 69 115 112 97 26 111 108 46
How disappointing! I thought that I had finally found the error. There is something about your system I don't understand, possibly the keyboard. Unfortunately, I am not in a position to test my ideas on Spanish keyboards. I think you need to contact MATLAB Support about this. Sorry I couldn't help more.
and,
unicode2native('Química, Matemáticas, Español.','latin1')
ans =
Columns 1 through 19
81 117 26 109 105 99 97 44 32 77 97 116 101 109 26 116 105 99 97
Columns 20 through 30
115 44 32 69 115 112 97 26 111 108 46
give me the same result. The same happens when using other alias, such as: 'latin2', 'latin3', and 'latin4'. MATLAB throws me the same result.
I though the same... most likely the 2007 Apple Western Spanish Keyboard is the problem. In such a case, I will try contacting the MATLAB Support so they may give me some workaround to solve my problem. Again, thank you very much for your kind of help.
At least I can do it on my machine now! Good luck.
Note: when you see a 26 in the output of unicode2native, that indicates a character which could not be translated to the target character set.

Iniciar sesión para comentar.

Try this in your code
feature('DefaultCharacterSet', 'UTF8') %# for all Character support
or try 'Windows-1250' insted UTF8
'Windows-1250' for Central European languages that use Latin script, (Polish, Czech, Slovak, Hungarian, Slovene, Serbian, Croatian, Romanian and Albanian)
Note:- that UTF-8 can be used for all languages and is the recommended charset on the Internet.

Categorías

Más información sobre Data Import and Export en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 26 de Abr. de 2011

Comentada:

el 2 de Mzo. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by