Friday, November 20, 2009

MATLAB 2007a with JRE 1.6 to solve the "CANNOT PASTE" issue

Hi all!

After many posts, here we are speaking again about Mathworks MATLAB R2007a, a glorious version of this remarkable programming environment for Scientific Computing.

This version of MATLAB is now a bit old, but many universities and then professors, research teams and students are still using it. Also my famous neighbour is still using it with its awesome license and he is still so kind to let me use it in change of maintainance work on his Linux machine. ;-)

In older posts I already wrote about some solutions to issues about this MATLAB version in times when it was "too new", or "too humble" for Compiz...
This is, I think, the first post about an issue caused by the fact this version is now becoming "too old".

Recently, for some needs, I dropped from openjdk (on Archlinux) switching to the closed version of Java.

In the meantime I was playing with Emacs so I decided to change in MATLAB che "Copy and Paste" keybindings in order to learn better the Emacs ones.
They didn't work so well, especially the "Paste" command.. (but it was caused by Java).
Anyway, after a second, I needed suddenly to be more productive in order to finish a work and sadly I had to come back to the Windows-like keybindings CTRL-X CTRL-V and CTRL-C.

But what a surprise when I discovered that either in the Command Windows and in the MATLAB Editor a "Paste" was permitted literally only once per session 8-|

Since it was my fault playing with the "Copy and Paste" keybindings, I spent hours checking, patching, deleting and recreating MATLAB's preferences files in order to try to revert all the "Copy and Paste Universe" back its previous "Time's Arrow"!

After weeks using an external editor now I discovered another error dealing with a call to the Helvetica font I didn't set in any preference... so I started MATLAB with the debug option and I looked for some forum solution to cope with that further issue.

While reading I find an advice by a user suggesting to use the system's native JRE instead of the MATLAB's one. And then my eyes opened and I asked myself: "Could it be the copy and paste issue caused by the Java versione included in MATLAB?"
So I checked which Java version was embedded in MATLAB R2007a and I found it is the 1.5

After all this story here you are how to fix all the misterious errors you can experience in MATLAB due to its old Java:

You only need to create a custom script for launching MATLAB in order not to modify the native one (it's possibile but it's not adviceable):

#!/bin/sh

# This was good for Compiz issues
# but I don't need it at the moment
# export AWT_TOOLKIT=MToolkit

# This is the magic environment variable to fill
# with your system's Java Installation directory
export MATLAB_JAVA=/opt/java/jre

# This is my matlab start command... probably only
# "matlab -desktop" on your system
/opt/matlabR2007a/bin/matlab -desktop

So that's all, if you start MATLAB with the MATLAB_JAVA environment variable pointing to your system's Java installation directory you (hopefully) will solve all the issues due to the old 1.5 Java embedded in the R2007a version.

At least, for me it worked, not showing anymore the Copy and Paste issue and the strange font issue at MATLAB's start.

Hope this will be useful for someone else ;-)

Keep on hackin'

2 commenti:

  1. Anonymous6:59 PM

    mille grazie ... it was a big "rompimento"

    ReplyDelete
  2. Anonymous6:57 AM

    Brilliant! This solved my problem!

    ReplyDelete