Displaying (in the prompt) latin characters, such as á, é, í, ó, ú, and ñ, using MATLAB R2010b/R2011a for mac
Mostrar comentarios más antiguos
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
Fernando Aguilar
el 4 de Sept. de 2016
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.
Walter Roberson
el 4 de Sept. de 2016
The success of using char(x) depends upon your locale, and upon your MATLAB version, and your font, and your feature('DefaultCharacterSet')
Walter Roberson
el 4 de Sept. de 2016
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.
Ricardo Prada
el 2 de Mzo. de 2017
Respuesta aceptada
Más respuestas (2)
Andrew Newell
el 26 de Abr. de 2011
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
Ricardo Prada
el 26 de Abr. de 2011
Ricardo Prada
el 27 de Abr. de 2011
Andrew Newell
el 27 de Abr. de 2011
It's R2010b on Mac OS 10.6.7 (Snow Leopard).
Andrew Newell
el 27 de Abr. de 2011
How is it not working?
Ricardo Prada
el 27 de Abr. de 2011
Ricardo Prada
el 27 de Abr. de 2011
Andrew Newell
el 27 de Abr. de 2011
No, you shouldn't need to change the locale - mine is American English.
Andrew Newell
el 27 de Abr. de 2011
What do you get if you type
unicode2native('Química, Matemáticas, Español.','latin1')
?
Andrew Newell
el 27 de Abr. de 2011
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.
Ricardo Prada
el 27 de Abr. de 2011
Ricardo Prada
el 27 de Abr. de 2011
Andrew Newell
el 27 de Abr. de 2011
Try 'ISO-8859-1'.
Andrew Newell
el 27 de Abr. de 2011
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.
Ricardo Prada
el 27 de Abr. de 2011
Ricardo Prada
el 27 de Abr. de 2011
Andrew Newell
el 27 de Abr. de 2011
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.
Ricardo Prada
el 27 de Abr. de 2011
Ricardo Prada
el 27 de Abr. de 2011
Andrew Newell
el 27 de Abr. de 2011
At least I can do it on my machine now! Good luck.
Walter Roberson
el 4 de Sept. de 2016
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.
Anandakumar Selvaraj
el 27 de Feb. de 2014
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
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!