How can I change the default character encoding? (MATLAB R2013b, Mac OSX)

Hello, I wanna use ISO-8859-1 encoding to be able to use Swedish characters like å,ä and ö. I read that MATLAB reads the default character encoding from the user settings in Mac OS. But I wanna use English in my OS, and just want to change the encoding in MATLAB.
feature('DefaultCharacterSet') returns US-ASCII by default.
When I try to change to ISO-8859-1 with feature('DefaultCharacterSet', 'ISO-8859-1') and check again with feature('DefaultCharacterSet') i get ISO-8859-1 , but I still cant use the swedish characters.
for instance:
disp('åäö') returns nothing, and
disp('hello åäö hello') returns hello hello
[EDIT]
I made it work when i created startup.m with feature('DefaultCharacterSet','ISO-8859-1'), although I still cant open directories (folders) with Swedish letters. I get the error: E rror using cd, (Name is nonexistent or not a directory)
Does this not depend on character encoding? Again, this is not a problem when I use Swedish language in OSX.

Risposte (1)

Open the system Language and Text preference. In the Input Sources area, select Swedish and whichever English you prefer (e.g., Canadian English for me.) In the system Keyboard preferences, you might want to tick on the bottom box, "Show Keyboard & Character Viewers in menu bar".
You should now have a little on the top menu bar, probably just to the left of the time. Click on it and on the drop-down menu that comes up, click on whichever keyboard you want to use. If you are not sure where the characters are, open the keyboard viewer from that same menu.
I am using ISO-8859-1 with English for my OS, and I can switch to other languages (including Swedish, I tested) when I want to.
In the system Language Preferences, in that last tab, the one that allows you to select keyboards, you might need to click the radio button to allow different encodings for each document. I have it set to use the same encoding, but then my default is ISO-8859-1 rather than US-ASCII

11 Commenti

Alright, so I solved one problem. I changed "Format Language" in "System Preferences" to Swedish. This made me be able to use å,ä,ö in disp and comments etc. (altough Format Language are supposed to control the way dates, times and numbers, so I dont know why it helped changing this option.)
I still have the problem with directories. Even though MATLAB now starts with ISO-8859-1 I can't open folders with å,ä and ö. I get the same error; Error using cd, (Name is nonexistent or not a directory) . Does this not depend on Character Encoding?
I seem to recall a problem along these lines with OS-X. My recollection is that OS-X does not store those directory names using those characters, and instead "canonicalizes" them to a pair, non-spacing-diacritc followed by non-diacritic character. Almost no-one else does it that way, but there is a clause in one standard that says it should be done. As those character pairs are what are stored, when you request å it tries to match the single character å against the decomposed pair and fails.
I do not recall seeing any MATLAB-level solution, but there might have been one (by calling a Java method, for example.)
Question to Fredrik: I have the exact same problem, exactly where did you find this option? I run Mavericks and can't seem to find anything called "format language". I want matlab to not change my "åäö" in to "???" as soon as I re-open a program.
Perhaps System Preferences -> Language & Text -> Formats -> Region
The choice of languages to use for dates is according to the Region you select. To see Swedish, I had to tick "Show all regions".
The one I am using (and not having display difficulties with) is a slightly modified Canada English (I like my dates in a different order.)
Thank you for your answer Walter, I just found "Format Language" under "Advanced", top of the list. I wonder why I didn't spot it the first time. And to confirm, it solved my problem!
Perhaps they changed the menu in Mavericks
Excuse me, I use matlab 2019a. How could I change default encoding? Because I can not find in prefferences the way to fix it..
@Ivan Mich: on which operating system?
Also, would it be possible for you to upgrade to R2019b? R2019b switched to using UTF-8 for .m files for everyone, which makes everything a lot easier.
@Ivan Mich Are you using MacOS Mavericks like was being discussed above? Are you using Windows 10 1306, prior to Windows 10 Creator Edition? Are you using Windows 10 20H2 ? One of the linuxes ?

Accedi per commentare.

Categorie

Scopri di più su Environment and Settings in Centro assistenza e File Exchange

Prodotti

Richiesto:

il 4 Dic 2013

Commentato:

il 23 Gen 2021

Community Treasure Hunt

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

Start Hunting!

Translated by