File Encoding in Matlab’s Editor

The Matlab 2014b editor does not offer any option to change the encoding of files. The editor always uses the system default. To change it anyway on Linux, you have to set the system variable LC_CTYPE (thanks to stackoverflow). E.g.

LANG="en_US.iso-8859-1" && /usr/local/bin/matlab -desktop

Fortunately you can use the command in a .desktop file in the Exec=... line (Ubuntu has a nice description how to add Matlab to your window managers menus).

On other systems you can use similar tricks, which you will find in the Matlab documentation. Of course that has a side effects, your file names should not contain any special characters as Matlab assumes your filesystem uses the given encoding as well.

Some solutions I found suggested to change the default character set in Matlab using an undocumented command:

feature('DefaultCharacterSet', 'ISO8859-1')

But this has no effect on the editor in the Matlab window. The figures are shown correctly then but the editor is still using your system’s default. So editing .m files which contain any special characters will not work correctly and will likely destroy all special characters.

Now I just need a way to change the end of line style of the files. That seems to be the windows style (“\r\n“) on all systems.

My Blog

Hello World,

for some time now I am involved in the development of KMyMoney. So a blog seems to be useful.

Currently I am adding the ability to use online banking for credit transfers. As I decided to implement this functions in the most elegant way I could imagine this takes some time. But the development is close to a point where it can be released. Hopefully I can write more about this shortly.

Greetings,
Chris