I'm using a computer running Ubuntu and I'm connected through ssh to a RedHat machine where I use Matlab in command line mode (matlab -nodesktop). Matlab version is (R2010a).

My problem occurs when I type any key which produces "special characters", such as ñ, á, etc...

I managed to solve this, by setting this alias to matlab:

alias mat 'xmodmap -e "keycode 47 = Escape" -e "keycode 34 = Escape"; matlab -nodesktop; setxkbmap;'

...but this solution makes these changes globally, and I cannot type those characters (as long as matlab is running) in any other application including terminals, browsers, etc.

I read that this is a problem for this version of Matlab, but in that case, a new question arises: if I use xmodmap in a terminal (xterm) connected to other machine, why are those changes spread globally to my session?

  • 1
    As Caleb explains, a mapping change with xmodmap applies to the whole X session, and there's no easy alternate way. Maybe if you explain the Matlab issue we can come up with a better workaround. – Gilles Apr 20 '11 at 20:05
  • When this problem happens I loose control of Matlab, because the prompt behaves as it should when the Enter key gets stuck. The only option is to suspend session (CTRL-z) and then kill the process. – nozimica Apr 20 '11 at 22:22

Check if your locale settings match on the local and remote machine: run echo $LC_CTYPE in a local terminal and in an ssh session. If they don't match, try again with Matlab with LC_CTYPE set to the correct value. If that doesn't work, try with export LC_CTYPE=C or with export LC_CTYPE=en_US (shot in the dark, I don't know the nature of the bug with Matlab).

If you're in a UTF-8 locale, try in an 8-bit locale such as latin1:

LC_CTYPE=en_US luit ssh redhat-host

If fiddling with locales doesn't help, try something more radical: run stty istrip in the terminal before starting Matlab. This strips the 8th bit off the characters you type. When you enter an accented letter, Matlab will receive a garbage ASCII character, but nothing that should confuse it. Note that you should do this in addition to switching to a latin-1 locale such as en_US; in other locales, in particular in UTF-8, the garbage characters can be control characters.

There are a lot of stty settings, but I can't think of one that would just cause non-ASCII characters to be ignored. If you experiment with stty, you can revert to sane defaults with stty sane. The changes are local to a terminal.

  • Your radical solution worked. With stty istrip, matlab receives those characters, and for "ñ" it prints C1... I don't need the special characters inside Matlab, but by accident they sometimes get pressed. So, this is a very good solution, and one that I didn't find anywhere else. Thanks! – nozimica Apr 21 '11 at 15:33
  • @nozimica: Note that in a UTF-8 locale (which you seem to be in since ñ is two bytes), some accented letters will end up sending a control character to Matlab (e.g. ś → E^[). That could be a problem, so I recommend doing both: switch to a latin1 locale and stty istrip. – Gilles Apr 21 '11 at 19:03
  • I've just tested, and ś and other special characters do no harm to the matlab session. In particular, ś prints just E. About the stty sane command, it doesn't restore the original settings, but stty -istrip does. Very good is the option to negate a command in stty just by prepending a -. Thanks again! – nozimica Apr 22 '11 at 20:01

The changes you are making are not local to Matlab. The command you setup an alias for edits the keymap of the current X session, then starts Matlab. The changes end up on your machine because you have x-forwarding properties in your ssh session that allow programs to talk to the upstream X server. You could just as easily run an xterm on the remote computer and it would launch locally, because that shell knows that it's upstream X session is through your SSH connection.

In fact if this were not the case, your keyboard map fix would do nothing at all. Your local X server is the right place to set that, and, as far as I know, the only place that will work.


Apparently, this bug was fixed for MATLAB R2010b(7.11). The bug report can be found behind an inconvenient (but free) MathWorks account login here:

Extended characters typed or pasted into a nodesktop instance of MATLAB running in a xterm causes infinite loop of prompts to be displayed (bug 624817).

  • 1
    (But to my disappointment, our university is still stuck on R2010a…) – Pyry Jahkola Jun 5 '11 at 8:51

I also had problems with special characters on matlab, running it like this solved it for me:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.