Advanced Matlab & Simulink: Part 1 - Installation on Ubuntu

Posted by hnqiu on December 17, 2019

Introduction

Matlab is a great tool for numerical computing and data processing in the field of engineering. It has abundant add-ons and toolboxes, among which Simulink is one of the most widely used packages. Simulink is a graphical programming environment for multi-domain system modelling and simulations.

I guess most people would use Matlab on Windows, but Matlab is actually a cross-platform application that can also run on MacOS and Linux systems. Personally I favor the use on MacOS and Ubuntu since I have been interfacing it with C++ programs.

A step-by-step Guide

Download Matlab from the MathWorks Download Center. In this example I will install the R2016b release on Ubuntu 16.04.

  • Download the Linux Installer as well as the Update package
    The Installer is a .zip file, while the update package is named .sh.
  • Unzip the installer and execute
    cd ${DownloadPath}
    unzip matlab_R2016b_glnxa64.zip -d matlab/
    cd matlab
    sudo ./install
    
  • Follow the prompts to choose the installation folder and toolboxes, etc., during which, remember to enable Symbolic Links in the shown-below step. If you forgot to do so, don’t panic, you can do it manually after completing the following steps.
    image
  • Activate Matlab
    When installation is completed, you should be prompted to activate Matlab. Once again, if you did not check the box, don’t panic, follow this step to activate it later.
  • Run the update package
    Since the R2016b is a previous release, there are some security updates to be installed as well.
    cd ${DownloadPath}
    chmod +x R2016b_Update_7_glnxa64.sh
    sudo ./R2016b_Update_7_glnxa64.sh
    

    This process may take a while. A successful message would be shown when it is completed:

    =============== UPDATE INSTALLATION SUCCEEDED ===============
    
  • Launch Matlab from Terminal
    matlab
    

Make up for your mistakes

If you have followed the previous step-by-step guide you should not have any problems running Matlab. However, you probably would not see my post unless you have already encountered some problems and are looking for solutions. Lucky for you, this is how you can fix your problems (hopefully).

matlab command not found

You have done everything (or so you thought): you have run the installer and activated your account; you have also run the update package. But when you launch Matlab, you get the command not found error. Now try this:

cd ~/usr/local/MATLAB/R2016b/bin
matlab

If Matlab is launched, it means the Matlab application is working fine. The only problem is the command matlab can not be recognized unless the terminal is in the path where the application is installed, which means during the installation, you probably forgot to check the ‘Symbolic Links’ (step 3 of the previous guide).
In order to make the command global, we can create a symbolic link to a system-wide path. Here is how you fix it:

sudo ln -s ~/usr/local/MATLAB/R2016b/bin/matlab ~/usr/local/bin/matlab

Launch Matlab again. The problem should be fixed.

Licensing error

This is another error you may get when you try to run the command matlab. This is because you did not activate Matlab (step 4 of the previous guide). Run this:

cd ~/usr/local/MATLAB/R2016b/bin
sudo ./activate_matlab.sh

and enter your account and credentials when prompted.

Customize the matlab command

You probably have noticed there is no graphical launcher for Matlab on Ubuntu and you have to launch it from the terminal. However, when you execute the command matlab, the command window would be hanging. You cannot use the terminal to execute other commands. If you choose to close the terminal, Matlab would be closed as well. This is so annoying. Can we fix it? Well, instead of running matlab, try this:

matlab & disown

After Matlab starts, you can type in other commands in the terminal! You can even close the terminal without affecting Matlab!

Now to make things easier, save the command into your .bashrc file:

echo 'alias matlab="matlab & disown"' >> ~/.bashrc

This is a one-time configuration. Once done, you can just achieve the same result by executing matlab.