Tips for MATLAB on Linux
Setting up MATLAB can be a hassle. On Linux systems some of the defaults settings can be rather baffling. Here are the first things I do after installing.
Install the matlab-support package
After installing MATLAB you may be frustrated to find that it doesn't appear in the launcher. To run it you need to open a terminal and manually run the matlab command. On Ubuntu-derived systems the matlab-support packages solves this. It creates the missing .desktop files to let the launcher know about MATLAB and offers to solve some common problems with MATLAB on Linux. Pi To install it simply run
sudo apt install matlab-support
Change the keyboard shortcuts
On Linux systems MATLAB uses emacs-like keyboard shortcuts. This might be great for emacs power users but makes life harder for the rest of the us. To switch back to more common shortcuts
- Open MATLAB preferences.
- In the MATLAB tree open Keyboard then Shortcuts and change the Active Settings dropdown from Emacs Default Set to Windows Default Set.
To change the default open Preferences. In the MATLAB tree open Fonts and change the Desktop Code Font
Change the autosave location
MATLAB will helpfully autosave our files for us. By default it does this by creating a copy of the file and appending a ~ to its name. These files however can create clutter your working directory. An alternative is to instruct MATLAB to save them all in a single folder.
- Open MATLAB preferences
- In the MATLAB tree open Editor/Debugger then Backup Files.
- Change the Location option from Source file directories to Single directory and set the target directory in the text box. I usually use a hidden folder in my MATLAB home directory so I set it to ~/home/Documents/MATLAB/.autosave.
Changing the date and time formats
Whilst America seems proud of its imperial units and weird way of writing dates the rest of world can't help but look on with a puzzled expression. By default MATLAB seems to completely disregard de system locale when presenting dates.
Whilst we can't force America to adopt the glorious metric system we can however instruct MATLAB to present dates in a reasonable manner.
- Open MATLAB preferences
- In the MATLAB tree open Command Window
- Check the Locale option in the Datetime Format section. If MATLAB was able to locate a sane locale changing it should be enough. In my case MATLAB was unable to locate a normal locale so I had to manually set the datetime and date formats.
- Set the Default date and time format to uuuu-MM-dd HH:mm:ss and the Default date only format to uuuu-MM-dd.
Forcing MATLAB to use the default browser for html pages
If you frequently use the Publish as HTML feature of MATLAB to share scripts and their results you may be frustrated that MATLAB doesn't us your browser of choice. To force to always use the default browser if you change it later on you can tell MATLAB to use the xdg-open command instead. This command always uses the system default apps to open any file type.
- Open MATLAB preferences
- In the MATLAB tree open Web and in System Web Browser set Command to xdg-open. You can also set it as the PDF Reader command.
Last working folder
It can be frustrating to have to manually navigate to your current project's working folder every time you re-open MATLAB. MATLAB can remember your current working folder and re-open it automatically.
- Open MATLAB preferences
- In the MATLAB tree open General and change the Initial Working Folder to Last working folder from previous MATLAB session.
startup.m files
One of the most underused features of MATLAB is startup.m files.
When MATLAB starts up it will look for a file named startup.m in the current working directory and run it automatically. You can use it to set project specific settings easily.
For example, I use it to disable some warnings caused by some tools I use (and can't modify) to avoid extraneous noise. Another common use it to load all the subdirectories that contain tools I am using in the current project instead of having to addpath() them manually.
You can find the startup file I put in the root of my MATLAB projects here