22

I'm trying to install a Matlab R2011a launcher for Unity in Ubuntu 12.04. I've tried this guide (although I know it's for 11.10 and mentions that even 11.10 is an unsupported OS for Matlab R2011a) but without any satisfactory solution.

This is my launcher file, /usr/share/applications/matlab.desktop:

#!/usr/bin/env xdg-open
[Desktop Entry]
Type=Application
Icon=/usr/share/icons/matlab.png
Name=MATLAB R2011a
Comment=Start MATLAB - The Language of Technical Computing
Exec=matlab -desktop
Categories=Development;

I open the dash panel and search for "matlab". This launcher is found among applications. I click it, and Matlab's splash screen shows up, but when it disappears the program doesn't start. (I've verified with htop that no matlab-processes are running in the background either.)

If I add

Terminal=true

to the launcher file, the program starts OK, and opens a terminal as well as Matlab. However, both the terminal and Matlab itself show up in the Launcher area, with the Matlab icon, so it looks like I have two Matlab instances running when really it's only one. (Actually, they show up as two different programs, and not just two instances of the same - the icons are independent, not grouped together.)

This is definitely not optimal. I had hoped to create a launcher I can lock to the launcher area, and then that same icon will be the icon for the active Matlab instance when the program is running.

How do I create a launcher for Matlab that works as expected?

Update: I was apparently a bit unclear on my symptoms, I'll try to clarify a little. I've also tried some suggestions from the answers, and further investigated what happens. My current setup (a launcher file with Terminal=true and Exec=matlab -desktop -nosplash &) renders the following behavior:

  1. I open Dash by pressing the Windows key on my laptop, and search for "matlab". It finds the launcher named "MATLAB R2011a". I click it.
  2. A terminal window opens, using the icon I referred to in the launcher file. Almost immediately, MATLAB's splash screen also opens, using the same icon (and thus being grouped with the terminal window in the launcher).
  3. The splash screen disappears and, so does one of the icons in the launcher. The MATLAB desktop environment opens, using a different version of the icon which is displayed next to the icon for the terminal window (not grouped with it).

I can lock the terminal window's icon to the launcher and successfully start MATLAB by clicking it, but it doesn't feel optimal that I start the program with one icon, and switch to it with another. I've also tried the following:

  • Exec without the ampersand & in the launcher command, but it didn't make a difference.
  • Executing matlab -nosplash manually from a terminal still shows the splash screen. (What, then, does the nosplash option really do?)
pomsky
  • 68,507
Tomas Aschan
  • 2,922
  • What happens when you run matlab manually in a Terminal window? – Eliah Kagan May 19 '12 at 13:51
  • @EliahKagan: That works perfectly fine. It doesn't seem to matter if I run matlab or matlab -desktop, either. – Tomas Aschan May 19 '12 at 15:35
  • I'm having the exact same problem with the icons. I also installed the Ubuntu package for matlab from the repos. I find it really weird that once you start matlab another icon is created and if you lock the new one to the launcher, the new one won't open matlab... – Felipe May 23 '12 at 18:53

5 Answers5

14

Garrett's answer almost works for me, but instead I have to use

StartupWMClass=sun-awt-X11-XFramePeer

This still gives an extra launcher icon while the splashscreen is visible (because the WM_CLASS of the spashscreen is just "MATLAB"), but then the window gets properly grouped under the launcher.

New instances of Matlab (started by terminal, or Synapse, or from another tty with export DISPLAY=:0) also get grouped under this launcher, and the launcher's quit option kills all of them.

I found this WM_CLASS value by using

$ xprop WM_CLASS

and then clicking on the Matlab window, a command I got from Superuser.

To prevent the temporary extra launcher icon, you can also add the -nosplash flag after the -desktop one.

So, my ~/.local/share/applications/MATLAB.desktop looks like this:

[Desktop Entry]
Version=1.0
Type=Application
Icon=matlab
Name=Matlab
Comment=Start MATLAB - The Language of Technical Computing
Exec=matlab -desktop -nosplash
Terminal=false
Categories=Development;
StartupNotify=true
StartupWMClass=sun-awt-X11-XFramePeer
X-Ayatana-Desktop-Shortcuts=New_Window;

Name[en_US]=MATLAB

[New_Window Shortcut Group]
Name=start a new MATLAB instance
Exec=matlab -desktop

This is on Ubuntu 12.10, with Matlab R2012b

7

That's very odd. matlab -desktop really ought to do the trick.

Approach 1: see what's wrong with the launcher

I have a working MATLAB icon in my Unity sidebar. I can click it, it maintains the correct icon and doesn't open a terminal. As far as I can see it is pretty much the same as your code, though:

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/usr/local/MATLAB/R2011b/bin/matlab -desktop
Name=MATLAB
Icon=/home/tomas/icons/Matlab_Logo.png

The above code is in matlab.desktop, which is placed in /usr/share/applications/. The only differences I see that could matter are (i) the Exec path, but if you installed symlinks during your MATLAB installations yours should work just fine and (ii) I'm running MATLAB R2011b.

Like you, I'm running Ubuntu 12.04.

In case I missed something, you could try to use my code to start MATLAB, who knows, it might work.

Approach 2: a dirty workaround with the terminal

You mentioned entering matlab -desktop in the terminal works (i.e. adding Terminal=true). However, that gives you two screens grouped under the MATLAB.

You could try to fix this by changing how you call the process. The key here would be the ampersand & symbol. What that does is execute the preceding code, not waiting for it to finish. Ideally, it would start the terminal, let the terminal start MATLAB and immediate close the terminal, leaving MATLAB running. What happens if you start matlab from the terminal with the ampersand after the line, or:

matlab -desktop &

If that works, you could try (i) making a launcher with Terminal=true and the above code or (ii) making a launcher that refers to a bash script, which in turn calls the above code.

For you, Approach 1 didn't help. If Approach 2 doesn't work either it might be good to play around a bit, see what you can and cannot do with the ampersand, terminal and bash scripts. I'm pretty much out of good ideas, but someone smarter than me might be able to help you out then.

Tomas
  • 1,069
  • I tried your code, but without success. Also, (i) I did install symlinks during installation of Matlab. (ii) That could of course be the difference that matters - unfortunately, this is an academic license and I R2011a is the latest edition available to me, so I can't test it with R2011b =( – Tomas Aschan May 21 '12 at 08:32
  • I just edited my post, adding another idea. Let us know how that works out for you. – Tomas May 22 '12 at 01:17
  • Thanks! However, it did not make much of a difference. I seem to have been a little unclear on my symptoms; please see the OP update for some clarification. – Tomas Aschan May 22 '12 at 09:35
  • Aha, so you can start MATLAB using that launcher you've created. It's just the icon that's wrong. I'm afraid that if you resort to the terminal solution described in Approach 2, you won't get the right icon. I had the exact same problem, but could call MATLAB using matlab -desktop (see Approach 1). For me, that summons MATLAB, with the splash screen, and the correct icon for the main interface. It is placed under the locked launcher. If you want the correct icon and can't run MATLAB through a launcher with matlab -desktop, I'm out of ideas. Will let you know if I come up with anything. – Tomas May 22 '12 at 22:12
  • How do you see that text corresponding to the .desktop file? – DBinJP Jan 24 '18 at 08:07
4

I installed a Matlab Configuration file/script from the Software Center. It lists the Matlab launcher in the dash and works perfectly for Matlab2011a in Ubuntu 12.04. But it is not working from the launcher. I mean, if you lock it on the launcher and try to start it from there then it won't work, at least it is not working for me. So I have to start it from the dash.

To install this, go to the Ubuntu Software Center, search for the Matlab, it should be the first one on the list (the icon is a Matlab logo). Just install it, and it will take care the rest.

  • 1
    Good tip! However, it comes with exactly the same problems as my self-created launcher. – Tomas Aschan May 21 '12 at 08:31
  • great, thanks @maqtanim! works like a charm for me (ubuntu 12.10 amd64) – amc Feb 26 '13 at 02:35
  • Worked perfectly for me (Matlab R2013a on 12.10). Before installing this I didn't even have a launcher. Link to Software Center: http://apt.ubuntu.com/p/matlab-support – Tobias Mar 15 '13 at 11:59
3

Here's what I did to get things working correctly starting with a fresh install (version R2010b on Ubuntu 12.04).

  1. Install the matlab-support package from the software center as suggested. Or you can use the following command: sudo apt-get install matlab-support.

  2. Create a local .desktop file: gedit ~/.local/share/applications/matlab.desktop. For some reason saving it in /usr/share/applications caused it to not work when I would first log in.

  3. Copy and Paste the following code and save. The important change is the StartupWMClass line.

    [Desktop Entry]
    Version=1.0
    Type=Application
    Icon=/usr/share/icons/matlab.png
    Name=Matlab
    Comment=Start MATLAB - The Language of Technical Computing
    Exec=matlab -desktop
    Terminal=false
    Categories=Development;
    StartupNotify=true
    StartupWMClass=com-mathworks-util-PostVMInit
    X-Ayatana-Desktop-Shortcuts=New_Window;
    
    [New_Window Shortcut Group]
    Name=New Matlab
    Exec=matlab -desktop
    
  4. Open the applications folder where you just saved the matlab.desktop file: nautilus ~/.local/share/applications.

  5. Drag and Drop the matlab.desktop file to the unity launcher.

  • This looks real promising! However, there's something more I need to do - after doing this, clicking the Matlab icon in my launcher does the following: 1) a splash window shows, with its own separate launcher icon, and the icon I clicked starts flashing (fading in and out). 2) the splash window, and it's icon disappears, and the launcher icon I continues flashing. 3) The icon stops flashing, and nothing happens. – Tomas Aschan May 24 '12 at 12:58
  • I have also made sure that the matlab.desktop file is owned by me (not root) and that all users have read and execute rights. – Tomas Aschan May 24 '12 at 12:58
  • However, if I start Matlab from the terminal or Guake, it does use the icon I just put in the launcher - so something is right =) – Tomas Aschan May 24 '12 at 13:00
  • The splash screen will show up on its own, but does go away. This is due to it having a different class than the Matlab virtual machine (main program).

    As far as not starting, I'm not sure. Especially since you say it starts in terminal (I'm assuming using the same command matlab -desktop)

    – Garrett Foster May 24 '12 at 19:45
  • Yes, I use the same command. matlab & also works without problems (i.e. the -desktop switch is not necessary when starting from terminal). – Tomas Aschan May 28 '12 at 02:20
1

I am maybe coming to this a little late, but I have managed to do this by adding an entry to the 'Main Menu' application. I listed it as an 'Application' and then provided the full path to the executable in the MATLAB directory as the Command.

I also had to add the flag '-desktop' (without quotes). In addition, I also had to use the '-glnx86' flag as I'm using the Student Version on a 64bit system, but that has also worked fine.

I then managed to get an icon from this website.

This can then be located in the application menu and dragged down into the launcher. The only thing that is acting a little strange is that when I click on it, another MATLAB icon appears in the launcher instead of just making use of the one already there. If anyone can find a way to solve this then that would be great... but I can live with it as it is.

Tim
  • 11