Difference between revisions of "Matlab"

From ArchWiki
Jump to: navigation, search
(Resolving start warnings/errors)
(Installing from the AUR package: not using AUR helpers is a given)
 
(218 intermediate revisions by 64 users not shown)
Line 1: Line 1:
[[Category:Mathematics and science (English)]]
+
[[Category:Mathematics and science]]
{{i18n|Matlab}}
+
[[zh-hans:Matlab]]
{{stub}}
+
[[ja:Matlab]]
== General installation ==
+
{{Related articles start}}
Use the following commands to mount and install Matlab. Note that the path to the install script should contain no spaces, or the install will fail. For graphical install and interface libxp is needed.
+
{{Related|Octave}}
 +
{{Related|Sage-mathematics}}
 +
{{Related|Mathematica}}
 +
{{Related articles end}}
 +
{{Style|unnecessarily verbose}}
 +
From the [http://www.mathworks.com/products/matlab/ official website]:
  
pacman -S libxp
+
:''MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.''
Install from iso file
 
modprobe loop
 
mount -o loop matu2k8b.iso /media/iso/
 
/media/iso/install
 
  
=== Install 32-bit Matlab on 64-bit system ===
+
== Overview ==
Unfortunately, 32-bit is the only version available to students; 64-bit versions are available if you pay more money.  These instructions have been updated for the student r2009A version - however the instructions should work with any current version of Matlab.  To start off with we need to install a bunch of lib32 packages, not all found with pacman.  Check the [[AUR]] for {{AUR|lib32-libxp}}.
 
  
$ pacman -S lib32-mesa
+
MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year,
$ pacman -S lib32-glibc
+
release names are composed of {{ic|R}}, the year of the release and {{ic|a}} or {{ic|b}}.
$ pacman -S lib32-libxmu
+
Since R2012b MATLAB has only been available for 64-bit Linux. Arch Linux is not officially supported.
$ pacman -S lib32-zlib
+
[http://www.mathworks.co.uk/support/sysreq/current_release/index.html]
$ pacman -S lib32-ncurses
 
$ pacman -S lib32-libxtst
 
$ pacman -S lib32-libxi
 
$ pacman -S lib32-libxrender
 
$ pacman -S lib32-libxfixes
 
$ pacman -S lib32-freetype2 lib32-fontconfig lib32-libxdamage
 
$ pacman -S lib32-libxpm
 
  
My system is not a fresh install so there may be some other packages needed.
+
== Installation ==
  
Once they are installed  
+
A complete copy of the MATLAB software must be obtained before it can be installed. The MATLAB software is available to licenses holders on both a DVD and through the [http://www.mathworks.com The MathWorks website]. In addition to the software a file installation key is required for installation. It is possible to install MATLAB either with the {{aur|matlab}} package from the [[AUR]] or from the MATLAB installation software directly. The advantage of the {{aur|matlab}} package is that it manages dependencies and some of the nuances of the installation process while installing directly from the MATLAB installation software can be done by regular users to their home directories and works for any release of MATLAB (the {{aur|matlab}} package only works for releases including and after R2010b).
  
$ ./install -glnx86
+
=== Installing from the MATLAB installation software ===
  
After fixing any library dependency problems, you will be able to guide the installer through the install process. If activation doesn't work in the installer you'll need to login to Wolfram's site and download a license file which you'll put in {MATLAB}/licenses. After the install process, you'll need to create a symbolic link because the installer oddly thinks it's installing the 64-bit version of Matlab:
+
The MATLAB installation software is self contained and does not require any additional packages to install in silent mode. To install with the GUI a working [[Xorg]] graphical display is necessary. [[Wayland]] is not currently supported yet. The installation is handled by the {{ic|install}} script. You can run the script as root to install MATLAB system-wide or your user to install it only for you.
  
$ cd {MATLAB}/sys/java/jre
+
MATLAB 2016a and earlier is not compatible with {{Pkg|ncurses}} 6, so you must install the {{AUR|ncurses5-compat-libs}} package. See [[#Segmentation fault on startup]] for more info.
$ ln -s glnx86 glnxa64
 
  
In the above, {MATLAB} should be replaced by the root directory you chose for your installation.
+
During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:
  
You'll also need to put another link in matlab's bin folder because despite asking matlab to install the 32bit version, it still thinks you want to use the 64bit one.
+
# ln -s /{MATLAB}/bin/matlab /usr/local/bin
  
  $ cd {MATLAB}/bin
+
Or you could add MATLAB install path to {{ic|PATH}} environment variable.
$ ln -s glnx86 glnxa64
 
  
After that you'll need to edit the {MATLAB}/bin/matlab script to get the java settings correct.  After the comments at the top of the file, you'll need the line
+
==== Desktop entry ====
  
export MATLAB_JAVA={Path of JRE}
+
Optionally create a [[desktop entry]]. The MIME type of MATLAB files is {{ic|text/x-matlab}}.
  
Where {Path of JRE} will be /opt/java/jre if you're using Sun's JRE.  The path is one level up from where rt.jar is located.  That is, rt.jar should be in /opt/java/jre/libs if you used /opt/java/jre for MATLAB_JAVA. In Matlab R2010a it works pretty well, if you use the intern JRE with
+
Start {{ic|matlab}} with:
  
export MATLAB_JAVA={Path of Matlab}/sys/java/jre/glnx86/jre
+
* {{ic|-desktop}} to run Matlab without a terminal.
 +
* {{ic|-nosplash}} to prevent the splash screen from showing up.
  
To run it, you'll need to:
+
In order for icons to appear correctly {{ic|StartupWMClass}} needs to be set in the desktop entry. To find it out start MATLAB, run {{ic|xprop {{!}} grep WM_CLASS}} and select the MATLAB window.
  
$ /{MATLAB}/bin/matlab -glnx86 -desktop
+
Example desktop entry:
  
At this point you may have to resolve more library dependencies or troubleshoot Java.  Your version of Matlab may need a specific version of Sun's JRE installed.
+
{{hc|matlab.desktop|
 +
[Desktop Entry]
 +
<nowiki>Version=2018a
 +
Type=Application
 +
Terminal=false
 +
MimeType=text/x-matlab
 +
Exec=matlab -desktop -nosplash
 +
Name=MATLAB
 +
Icon=matlab
 +
Categories=Development;Math;Science
 +
Comment=Scientific computing environment
 +
StartupNotify=true
 +
</nowiki>
 +
}}
  
=== General ===
+
If one need to set environment variable, one could prepend {{ic|env}} in {{ic|Exec}}, for example, to system's libfreetype:
As one installs matlab, it might complain that there isn't a package, for the most part just look at the package name and then install it with pacman, or in the case of x86_64 there are some libraries only in AUR.
+
{{bc|
 +
<nowiki>Exec=env LD_PRELOAD=/usr/lib/libfreetype.so.6 matlab
 +
</nowiki>
 +
}}
  
==== Resolving start warnings/errors ====
+
One might wanna use system's {{ic|libstdc++}}.
  
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing /lib64/libc.so.6 library, this can be resolved by:
+
=== Installing from the AUR package ===
  
$ ln -s /lib/libc.so.6 /lib64
+
The EULA for the proprietary MATLAB software is restrictive. The {{aur|matlab}} package from the [[AUR]] is designed to allow MATLAB to be integrated into and managed by Arch. The package should be built on the system on which it is going to be installed and the package should be deleted from the installation location and the [[Pacman]] cache following installation. Distributing the package is a clear violation of the EULA.
  
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." I had to point Matlab to my system JVM in order to solve the problem (confirmed to work with the jdk7-openjdk package).
+
The {{aur|matlab}} package from the [[AUR]] defaults to building a package for the most recent 64-bit release of MATLAB, one could also install old releases, eg. {{aur|matlab-r2015b}}. The {{aur|matlab}} package from the [[AUR]] requires that both the MATLAB installation software and the file installation key are available in the source directory.
  
 +
In order to install Matlab from AUR, download the PKGBUILD file from AUR. Download the zip file containing the Matlab installer and name it <tt>matlab.zip</tt>. Then download the .lic file: Go in [https://mathworks.com/mwaccount/ your MathWorks account] and click on the license number you want to use. Then, go to the Install and Activate tab and select "Activate to Retrieve License File". Follow the instructions and download the license file needed for the installation and name the file <tt>matlab.lic</tt>. Also, the File Installation Key (FIK) is displayed: copy-paste it in a empty file and name it <tt>matlab.fik</tt>. For more details, refer to the PKGBUILD file.
 +
 +
== Configuration ==
 +
 +
=== Java ===
 +
 +
The MATLAB software is bundled with a JVM and therefore it is not necessary to install [[Java]]. The JVM version supported by MATLAB is listed in [https://ww2.mathworks.cn/support/compilers.html System Requirements & Platform Availability] or simply type {{ic|version -java}} in MATLAB. One could set the {{ic|MATLAB_JAVA}} environment variable to use custom JVM, for example, to specify the {{pkg|jre8-openjdk}} JRE, launch MATLAB with:
 +
 +
$ env MATLAB_JAVA=/usr/lib/jvm/java-8-openjdk/jre matlab
 +
 +
=== OpenGL acceleration ===
 +
 +
MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate [[video drivers]] need to be installed along with the OpenGL utility library {{Pkg|glu}} package. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. To check if MATLAB is making use of hardware based OpenGL acceleration run:
 +
 +
$ matlab -nodesktop -nosplash -r "opengl info; exit" | grep Software
 +
 +
If "software rendering" is not "false", then there is a problem with your hardware acceleration. If this is the case make sure OpenGL is configured correctly on the system. This can be done with the {{ic|glxinfo}} program from the {{Pkg|mesa-demos}} package:
 +
 +
$ glxinfo | grep "direct rendering"
 +
 +
If "direct rendering" is not "yes", then there is likely a problem with your system configuration.
 +
 +
If glxinfo works but not matlab, you can try to run:
 +
$ export LD_PRELOAD=/usr/lib/libstdc++.so; export LD_LIBRARY_PATH=/usr/lib/xorg/modules/dri/; matlab -nodesktop -nosplash -r "opengl info; exit" | grep Software
 +
 +
If its works, you can edit Matlab launcher script to add:
 +
 +
export LD_PRELOAD=/usr/lib/libstdc++.so
 +
export LD_LIBRARY_PATH=/usr/lib/xorg/modules/dri/
 +
 +
=== Sound ===
 +
 +
To confirm that MATLAB is able to use the default soundcard to present sounds run:
 +
 +
$ matlab -nodesktop -nosplash -r "load handel; sound(y, Fs); pause(length(y)/Fs); exit" > /dev/null
 +
 +
This should play an except from Handel's "Hallelujah Chorus." If this fails make sure [[ALSA]] is properly configured. This can be done with the {{ic|speaker-test}} program from the {{Pkg|alsa-utils}} package from the [[official repositories]]:
 +
 +
$ speaker-test
 +
 +
If you do not hear anything, then there is likely a problem with your system configuration.
 +
 +
=== GPU computing ===
 +
 +
MATLAB can take advantage of [http://www.mathworks.co.uk/discovery/matlab-gpu.html CUDA enabled GPUs] to speed up applications. In order to take advantage of a supported GPU install the {{Pkg|nvidia}}, {{Pkg|nvidia-utils}}, {{Pkg|ocl-icd}}, {{Pkg|opencl-nvidia}}, and {{Pkg|cuda}} packages from the [[official repositories]]. To check if MATLAB is able to utilize the GPU run:
 +
 +
$ matlab -nodesktop -nosplash -r "x=rand(10, 'single'); g=gpuArray(x); Success=isequal(gather(g), x), exit"  | sed -ne '/Success =/,$p'
 +
 +
=== Install supported compilers ===
 +
 +
In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the {{ic|gcc}}, {{ic|g++}}, {{ic|gfortran}}, and {{ic|jdk}} compilers must be installed. Details about the supported compilers for the [https://www.mathworks.com/support/compilers.html current release] and [https://www.mathworks.com/support/sysreq/previous_releases.html previous releases] are available online. Many of the supported {{ic|gcc}}, {{ic|g++}}, {{ic|jdk}} compiler versions for past MATLAB releases are available from the [[AUR]] (e.g., {{AUR|gcc43}}, {{AUR|gcc44}}, {{AUR|gcc47}}, {{AUR|gcc49}}and {{AUR|jdk6}}), while past versions of the {{ic|gfortran}} compilers are not packaged.
 +
 +
To use previous versions of the the {{ic|gcc}}, {{ic|g++}}, and {{ic|gfortran}} compilers with MEX files, edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurrences of {{ic|<nowiki>CC='gcc'</nowiki>}} with {{ic|<nowiki>CC='gcc-4.X'</nowiki>}}, {{ic|<nowiki>CXX='g++'</nowiki>}} with {{ic|<nowiki>CXX='g++-4.X'</nowiki>}}, and {{ic|<nowiki>FC='gfortran'</nowiki>}} with {{ic|<nowiki>FC='gfortran-4.X'</nowiki>}}, where {{ic|X}} is the compiler version appropriate for the particular MATLAB release.
 +
 +
{{Note|Newer versions of Matlab (at least 2017a) doesn't seem to respect the {{ic|${MATLAB}/bin/mexopts.sh}} customization. Instead it uses {{ic|${MATLAB}/bin/glnxa64/mexopts/LANG_glnxa64.xml}} file.}}
 +
 +
{{Note|Though, it's no officially supported, one could still use higher version of compiler, and ignore the warnings.}}
 +
 +
=== Help browser ===
 +
 +
The help browser uses valuable slots in the dynamic thread vector and causes competition with core functionality provided by libraries like the BLAS that also depend on the dynamic thread vector. The help browser can be configured to use fewer slots in the dynamic thread vector with
 +
 +
>> webutils.htmlrenderer('basic');
 +
 +
This is a persistent change and to reverse it use
 +
 +
>> webutils.htmlrenderer('default');
 +
 +
=== Garbled Interface ===
 +
 +
export J2D_D3D=false
 
  export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre
 
  export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre
  
== OpenGL Acceleration ==
+
== Troubleshooting ==
 +
 
 +
=== Static TLS errors ===
 +
 
 +
MATLAB has a number of libraries that have been compiled with static thread local storage (TLS) including the help broswer {{ic|doc}} and the BLAS libraries. For example,
 +
 
 +
>> doc('help');
 +
>> ones(10)*randn(10);
 +
Error using  *
 +
BLAS loading error:
 +
dlopen: cannot load any more object with static TLS
 +
 
 +
is related to the bugs:
 +
 
 +
* [http://www.mathworks.de/support/bugreports/961964 961964] for which patched libraries are available from [http://www.mathworks.de/support/bugreports/license/accept_license/5730?fname=attachment_961964_12b_13a_13b_14a_glnxa64_2014-01-30.zip&geck_id=961964 MathWorks]
 +
* [http://www.mathworks.com/support/bugreports/1003952 1003952] for which workarounds exist
 +
 
 +
A more general solution of recompiling {{ic|glibc}} has also been suggested. [http://stackoverflow.com/a/19468365/2787723]
 +
 
 +
=== MATLAB crashes when displaying graphics ===
 +
 
 +
To identify this error, start MATLAB with
 +
 
 +
LIBGL_DEBUG=verbose matlab
 +
 
 +
from the terminal and try to collect OpenGL information with {{ic|opengl info}} from the MATLAB command prompt. If it crashes again and there is an output line like
 +
 
 +
libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed
 +
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6:
 +
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))
 +
 
 +
then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by
 +
 
 +
cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64
 +
sudo unlink libstdc++.so.6
 +
sudo ln -s /usr/lib/libstdc++.so.6
 +
 
 +
If MATLAB still crashes or corrupts graphics (during startup or when plotting), make sure Java's 2D OpenGL rendering is disabled.
 +
The environment variable {{ic|_JAVA_OPTIONS}} should not contain {{ic|1=-Dsun.java2d.opengl=true}}.
 +
 
 +
=== Blank/grey UI when using WM (non-reparenting window manager) ===
 +
 
 +
This is a common issue in a number of window managers. (DWM, Awesome, bspwm) Java does not play well with these window managers. There are two methods.
 +
 
 +
First try setting the environment variable by running
 +
 
 +
$ export _JAVA_AWT_WM_NONREPARENTING=1
 +
 
 +
If Matlab works afterwards, export the variable in your {{ic|.xinitrc}}.
 +
 
 +
If it doesn't resolve, you have to fool Java into thinking the WM is named LG3D. (It's an old, depreciated WM that Java applications ironically support) Clean the previous environment variable, install the [http://tools.suckless.org/wmname wmname] utility, and run.
 +
 
 +
wmname LG3D
 +
 
 +
Try running Matlab. If it works, put the fix in your starting script. ({{ic|.xinitrc}}, {{ic|bspwmrc}} and similar should be OK) Do note that other applications (such as {{ic|neofetch}}, or {{ic|tdrop}}) will think your WM is named LG3D, so you will have to configure them accordingly. Another solution is to run the command only before launching Matlab, and fixing the name after you are done with Matlab.
 +
 
 +
If it doesn't work, try the combination of both. (The second line works in bspwm) If it still doesn't work, try googling similar issues with java in general.
 +
 
 +
=== Garbled or invisible text ===
 +
 
 +
Set the environment variable <code>J2D_D3D</code> to <code>false</code>[https://stackoverflow.com/questions/22737535/swing-rendering-appears-broken-in-jdk-1-8-correct-in-jdk-1-7].
 +
 
 +
In newer versions of MATLAB (R2015b) [https://www.reddit.com/r/archlinux/comments/3yaga8/matlab_installer_bonked/] this also requires setting <code>MATLAB_JAVA</code> to something openjdk based. Example:
 +
 
 +
export J2D_D3D=false
 +
./bin/glnxa64/install_unix -javadir /usr/lib/jvm/java-7-openjdk/jre
 +
 
 +
=== Corrupted text and fonts in menus and fields ===
 +
If you notice that the menus or the input fields are corrupted or not appearing correctly then you can try to activate the ''"'''Use antialiasing to smooth desktop fonts'''"'' option in Matlab preferences, it seems to solve the problem. Go to '''''Preferences -> Matlab -> Fonts''''' and activate it. You will need to restart Matlab in order to take affect.
 +
 
 +
=== Installation ===
 +
As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with [[Pacman]], or in the case of x86_64 there are some libraries only in [[AUR]].
 +
 
 +
=== Install-time library errors ===
 +
* Make sure that the symlink {{ic|bin/glnx64/libstdc++.so.6}} is pointing to the correct version of {{ic|libstdc++.so.xx}} (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').
 +
 
 +
* Make sure the device you're installing from is not mounted as {{ic|noexec}}
 +
 
 +
* If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.
 +
 
 +
=== Resolving start warnings/errors ===
 +
 
 +
* Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing {{ic|/lib64/libc.so.6}} library, this can be resolved by:
 +
 
 +
# ln -s /lib/libc.so.6 /lib64
 +
 
 +
* Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the {{Pkg|jdk7-openjdk}} package):
 +
 
 +
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre
 +
 
 +
* Matlab R2017b with an up-to-date Arch Linux (as of September 30, 2017) fails on startup with the familiar "Failure loading desktop class." A solution is to install outdated versions of the libraries in the packages {{Pkg|cairo}} (1.14.10 works) and {{Pkg|harfbuzz}} (1.4.6 works) to a local directory and add them to the LD_LIBRARY_PATH for matlab (See also: [https://bbs.archlinux.org/viewtopic.php?id=228944]):
 +
 
 +
LD_LIBRARY_PATH="/opt/matlab/outdatedLibraries/:$LD_LIBRARY_PATH" /opt/matlab/R2017b/bin/matlab
 +
 
 +
=== Segmentation fault on startup ===
 +
 
 +
If Matlab (R2016a or earlier) stops working after upgrading {{Pkg|ncurses}} to v6.x, [[install]] the {{AUR|ncurses5-compat-libs}} package. See [https://bbs.archlinux.org/viewtopic.php?id=202575 BBS#202575].
 +
 
 +
In newer versions (e.g. R2017b), the issue could also be due to a font display failing to load.
 +
Try moving the libfreetype.so.6 font display file in $MATLAB/bin/glnxa64/ to an 'exclude' directory; see [https://bbs.archlinux.org/viewtopic.php?id=231299 BBS#231299].
 +
 
 +
ncurses compatibility layer is not required anymore for R2018a.
 +
 
 +
=== Hangs on rendering or exiting with Intel graphics ===
 +
 
 +
Some users have reported issues with DRI3 enabled on Intel Graphics chips. A possible workaround is to disable DRI3 and run MATLAB with hardware rendering on DRI2; to do so, launch MATLAB with the environment variable LIBGL_DRI3_DISABLE set to 1:
 +
 
 +
LIBGL_DRI3_DISABLE=1 /{MATLAB}/bin/matlab
 +
 
 +
If the previous workaround does not work, the issue can be circumvented by selecting software rendering with the MATLAB command (beware, performance may be very poor when doing e.g. big or complex 3D plots):
 +
 
 +
opengl('save','software')
 +
 
 +
See [https://bugzilla.redhat.com/show_bug.cgi?id=1357571] and [https://bugs.freedesktop.org/show_bug.cgi?id=96671] for more.
 +
 
 +
=== Addon manager not working ===
 +
This section is relevant for both R2017b and R2018a.
 +
 
 +
Addon manager requires the {{AUR|libselinux}} package to work.
 +
 
 +
Since upgrade from pango-1.40.5 to pango-1.40.6, the MATLABWindow application (responsible for Add-On Manager, Simulation Data Inspector and perhaps something else) cannot be started. [https://bugs.archlinux.org/task/54257]
 +
A workaround is to point MATLAB shipping glib libraries to those glib libraries from your system. There are 5 of those libraries in {{ic|matlabroot/R2017b/cefclient/sys/os/glnxa64}}, namely, as of R2017b:
 +
 
 +
libgio-2.0.so
 +
libglib-2.0.so
 +
libgmodule-2.0.so
 +
libgobject-2.0.so
 +
libgthread-2.0.so
 +
 
 +
Make it so that these symlinks are pointing to your system glib libraries instead of versions located in {{ic|matlabroot/R2017b/cefclient/sys/os/glnxa64}}.
 +
On a standard arch install the local files reside in {{ic|/usr/lib/}}.
 +
 
 +
Do not forget to update the {{ic|*.0}} links as well.
 +
 
 +
Relinking of "libfreetype.so.6" is also necessary to open these interfaces. This is found in {{ic|matlabroot/R2017b/bin/glnxa64/}}.
 +
 
 +
If the window opens but is blank, consider switching the html renderer to: " webutils.htmlrenderer('basic');" as described in [[#Help browser]].
 +
 
 +
=== Live Script Errors ===
 +
If you get the error when attempting to load or create a LiveScript:
 +
  {{ic|Viewing matlab live script files is not currently supported by this operating system configuration}}
 +
*It could be because of broken symlinks of {{Pkg|libgcrypt}} and other dependencies, after system updates. On the first start of the Live Editor the components are extracted and these libary symlinks are created (if not existing). A solution is to simply delete the whole folder containing the broken symlinks and the extracted components, which are in the installation directory (represented by {{ic|$MATLABROOT}}) under:
 +
$MATLABROOT/sys/jxbrowser-chromium
 +
Or if the installation directory is not user writable in:
 +
~/.matlab/R2017b/HtmlPanel
 +
Matlab will then regenerate the contents on the next Live Editor start.
 +
*Also the steps in [[#Addon manager not working]] may resolve the issue.
 +
*If the above does not help, execute in the command window
 +
>> com.mathworks.mde.liveeditor.widget.rtc.CachedLightweightBrowserFactory.createLightweightBrowser()
 +
to get a more detailed error message.
 +
* A debugging console can be opened with
 +
>> com.mathworks.mde.webbrowser.HtmlPanelDebugConsole.invoke;
 +
 
 +
=== Using webcam/video device ===
 +
Make sure the correct support package addons are installed (webcam or OS Generic Video Interface for example). If running matlab as a user, make sure your user has write permissions to wherever the support packages are being downloaded and installed.
 +
 
 +
At least Matlab 2016b doesn't recognize webcams or imaq adapters correctly without gstreamer0.10. The gstreamer0.10 can be found in the aur and installed as a work around.
 +
 
 +
Since MATLAB R2017a, Image Acqusition Toolbox is using GStreamer library version 1.0. It previously used version 0.10.
 +
 
 +
In general, USB Webcam Support Package does a better job working with UVC and built-in cameras than OS Generic Video Interface Support Package.
 +
 
 +
'''Warning:''' As of 2018-08-15 updating gst from 1.14.0 to 1.14.2 breaks video device operation (MATLAB doesn't see the video device anymore). Downgrading fixes this.
 +
 
 +
=== MATLAB hangs for several minutes when closing Help Browser ===
 +
Since upgrade of glibc from 2.24 to 2.25, MATLAB (at least R2017a) hangs when closing Help Browser. The issue is related to the particular version of jxbrowser-chromium shipped with MATLAB.
 +
This issue is still present with glibc 2.26 and MATLAB R2017b and R2018a.
 +
 
 +
To fix this issue, download the [https://www.teamdev.com/jxbrowser latest jxbrowser] and replace the following jars from MATLAB:
 +
 
 +
matlabroot/java/jarext/jxbrowser-chromium/jxbrowser-chromium.jar
 +
matlabroot/java/jarext/jxbrowser-chromium/jxbrowser-linux64.jar
 +
 
 +
MATLAB should automatically unpack those jars into {{ic|matlabroot/sys/jxbrowser-chromium/glnxa64/chromium}} when first opening Help Browser.
 +
Remove {{ic|matlabroot/sys/jxbrowser-chromium/glnxa64/chromium}} directory to make sure MATLAB uses the latest jxbrowser.
 +
 
 +
Unfortunately, this workaround doesn't work in R2017b anymore. Going deeper into investigation of this issue, it is related to a crash of one of jxbrowser-chromium processes. The parent process of jxbrowser-chromium then sits there and waits for response from a process that is already dead. This causes MATLAB main window to freeze. You can easily unfreeze MATLAB by manually killing all leftover jxbrowser-chromium processes.
 +
 
 +
I've come up with this simple script that uses inotify and waits for user to close Help browser in MATLAB. It triggers when user closes Help browser and sends kill signal to all leftover jxbrowser-chromium processes:
 +
 
 +
#!/usr/bin/bash
 +
 +
if [ -z "$1" ]; then
 +
REL=R2017b
 +
else
 +
REL=$1
 +
fi
 +
 +
JXPATH="/path/to/MATLAB/$REL/sys/jxbrowser-chromium/glnxa64/chromium"
 +
CMD="inotifywait -m -e CLOSE $JXPATH/resources.pak"
 +
 +
#Exit if the daemon is already active
 +
if ! pgrep -f "$CMD" > /dev/null; then
 +
#Wait for user to close Help Browser, then killall leftover jxbrowser processes
 +
$CMD |
 +
while read line
 +
do
 +
killall "$JXPATH/jxbrowser-chromium"
 +
done
 +
else
 +
exit
 +
fi
 +
 
 +
I run this script as part of my MATLAB start script like that:
 +
~/bin/unfreeze_matlab.sh R2017b &
 +
 
 +
To make sure that this background job is killed when I exit MATLAB, I use this in the beginning of MATLAB start script:
 +
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
 +
 
 +
=== Some dropdown menus cannot be selected ===
 +
In some interfaces - such as Simulation Data Inspector or Simulink Test Manager - nothing happens when choosing an item in dropdown menu (for example, when trying to change a number of subplots in Simulation Data Inspector). To work around this issue, hold down the Shift key while clicking the item in dropdown menu.
 +
 
 +
=== Not starting - licensing error===
 +
In case MATLAB will not start from a [[desktop environment]] by the call of its [[desktop file]] one should see the output as you start it from the terminal.
 +
 
 +
For a ''Licensing error'' such as:
 +
 
 +
{{hc
 +
|# matlab|
 +
MATLAB is selecting SOFTWARE OPENGL rendering.
 +
License checkout failed.
 +
License Manager Error -9
 +
This error may occur when:
 +
-The hostid of this computer does not match the hostid in the license file.
 +
-A Designated Computer installation is in use by another user.
 +
If no other user is currently running MATLAB, you may need to activate.
 +
 
 +
Troubleshoot this issue by visiting:
 +
http://www.mathworks.com/support/lme/R2017a/9
 +
 
 +
Diagnostic Information:
 +
Feature: MATLAB
 +
License path: /home/<USER>/.matlab/R2017a_licenses/license_<NUM>_R2017a.lic:/home/<USER>/.matlab/R2017a_licenses/lice
 +
nse_Darkness_<NUM>_R2017a.lic:/opt/MATLAB/R2017a/licenses/license.dat:/opt/MATLAB/R2017a/licenses/*
 +
.lic
 +
Licensing error: -9,57.
 +
}}
 +
 
 +
A re-activation might solve the problem.
 +
 
 +
=== MATLAB crashes with "Failure loading desktop class" on startup ===
 +
In case MATLAB won't start and starting it from command line gives you the following error:
 +
{{hc
 +
|$ matlab|
 +
Fatal Internal Error: Internal Error: Failure occurs during desktop startup. Details: Failure loading desktop class.
 +
}}
 +
and you have the option [[Java#GTK_LookAndFeel|{{ic|1=-Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel}}]] set in your {{ic|_JAVA_OPTIONS}} environment variable, start MATLAB with
 +
 
 +
$ _JAVA_OPTIONS= matlab
 +
 
 +
If this works, add the line
 +
 
 +
export _JAVA_OPTIONS=
 +
 
 +
to your MATLAB launcher script. Optionally re-add other Java options.
 +
 
 +
=== Unable to type in text fields of interfaces based on MATLABWindow ===
 +
Since R2018a, it is not possible to type text in interfaces based on MATLABWindow - like Signal Editor, Add-Ons Explorer and others.
 +
MATLABWindow and MATLAB's webwindow infrastructure is based on Chromium Embedded Framework, and it looks like a known and long standing bug: https://bitbucket.org/chromiumembedded/cef/issues/2026/multiple-major-keyboard-focus-issues-on
 +
 
 +
One possible workaround is to switch focus from the MATLABWindow to another window and then switch back - so that you can type.
 +
 
 +
== Matlab in a systemd-nspawn ==
 +
Matlab can be run within a systemd-nspawn container to maintain a static system and avoid the library issues that often plague matlab installs after significant updates to libraries in Arch. Refer to [[Systemd-nspawn]] for detailed information on setting up such containers.
 +
 
 +
The following lists instruction to get a MATLAB 2017b install running in a minimal debian 9 environment. It assumes matlab is already installed as normal in "/usr/local/MATLAB/R2017b".
 +
 
 +
Use [[Xhost]] to allow the nspawn environment to use the existing X server instance.
 +
 
 +
Create a minimal debian environment in a folder ("deb9" here) with:
  
Once Matlab is installed type the following in the matlab interpreter:
+
$ debootstrap --arch=amd64 stretch deb9
  
<pre>opengl info</pre>
+
Set a password for the root user and then boot the environment with:
  
The output should be similar to the following:
+
$ systemd-nspawn --bind-ro=/dev/dri --bind=/tmp/.X11-unix --bind=/usr/local/MATLAB/ -b -D deb9
  
<pre>
+
Install the following packages to have the requisite libraries in the nspawn environment for MATLAB. "mesa-utils" and "usbutils" can be installed to debug graphics acceleration and usb interfaces for I/O with MATLAB.
Version        = 2.0 Mesa 7.8.2
 
Vendor          = Advanced Micro Devices, Inc.
 
Renderer        = Mesa DRI R600 (RV710 9552) 20090101 x86/MMX/SSE2 TCL DRI2
 
MaxTextureSize  = 4096
 
Visual          = 0xcb (TrueColor, depth 24, RGB mask 0xff0000 0xff00 0x00ff)
 
Software        = false
 
# of Extensions = 107
 
  
Driver Bug Workarounds:
+
$ apt-get install xorg build-essential libgtk2.0-0 libnss3 libasound2
OpenGLBitmapZbufferBug    = 0
 
OpenGLWobbleTesselatorBug = 0
 
OpenGLLineSmoothingBug    = 0
 
OpenGLClippedImageBug    = 0
 
OpenGLEraseModeBug        = 0
 
</pre>
 
This will vary with card you are using, but the important part is "Software = false". If it's not "false" for you, then there is a problem with your hardware acceleration.
 
  
=== Nvidia ===
+
Install the MATLAB-support (from contrib source) package in the environment for some convenient integration.
  
With an nVidia card, the output should be similar to this:
+
  $ apt-get install matlab-support
<pre>
 
>> opengl info
 
Version        = 2.1.2 NVIDIA 177.82
 
Vendor          = NVIDIA Corporation
 
Renderer        = Quadro NVS 140M/PCI/SSE2
 
MaxTextureSize = 8192
 
Visual          = 0x21 (TrueColor, depth 16, RGB mask 0xf800 0x07e0 0x001f)
 
Software        = false
 
# of Extensions = 144
 
  
Driver Bug Workarounds:
+
Set the $DISPLAY variable to use your existing X server instance.
OpenGLBitmapZbufferBug    = 0
 
OpenGLWobbleTesselatorBug = 0
 
OpenGLLineSmoothingBug    = 0
 
OpenGLClippedImageBug    = 1
 
OpenGLEraseModeBug        = 0
 
</pre>
 
  
With the nVidia card all it required to start working was to copy the libGLU.so from the matlab installed library /usr/local/matlab/sys/opengl/lib/glnx86/libGLU.so to /usr/lib directory. Note that in x86_64 this might be a different directory.
+
$ export DISPLAY=:0
  
{{Note|Although, not thoroughly tested, using lib32-nvidia-utils seems to work as well.}}
+
MATLAB can be launched from within the environment normally by using the binary at $MATLABROOT/bin.

Latest revision as of 10:59, 20 September 2018

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements. See Help:Style for reference.Tango-edit-clear.png

Reason: unnecessarily verbose (Discuss in Talk:Matlab#)

From the official website:

MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java.

Overview

MATLAB is proprietary software produced by The MathWorks and requires a license to obtain, install, and activate. New versions of MATLAB are released twice a year, release names are composed of R, the year of the release and a or b. Since R2012b MATLAB has only been available for 64-bit Linux. Arch Linux is not officially supported. [1]

Installation

A complete copy of the MATLAB software must be obtained before it can be installed. The MATLAB software is available to licenses holders on both a DVD and through the The MathWorks website. In addition to the software a file installation key is required for installation. It is possible to install MATLAB either with the matlabAUR package from the AUR or from the MATLAB installation software directly. The advantage of the matlabAUR package is that it manages dependencies and some of the nuances of the installation process while installing directly from the MATLAB installation software can be done by regular users to their home directories and works for any release of MATLAB (the matlabAUR package only works for releases including and after R2010b).

Installing from the MATLAB installation software

The MATLAB installation software is self contained and does not require any additional packages to install in silent mode. To install with the GUI a working Xorg graphical display is necessary. Wayland is not currently supported yet. The installation is handled by the install script. You can run the script as root to install MATLAB system-wide or your user to install it only for you.

MATLAB 2016a and earlier is not compatible with ncurses 6, so you must install the ncurses5-compat-libsAUR package. See #Segmentation fault on startup for more info.

During the installation, you are asked if you want symlinks to be created. If you did not choose to do so, you can now manually create a symlink in /usr/local/bin to make it easier to launch in terminal:

# ln -s /{MATLAB}/bin/matlab /usr/local/bin

Or you could add MATLAB install path to PATH environment variable.

Desktop entry

Optionally create a desktop entry. The MIME type of MATLAB files is text/x-matlab.

Start matlab with:

  • -desktop to run Matlab without a terminal.
  • -nosplash to prevent the splash screen from showing up.

In order for icons to appear correctly StartupWMClass needs to be set in the desktop entry. To find it out start MATLAB, run xprop | grep WM_CLASS and select the MATLAB window.

Example desktop entry:

matlab.desktop
[Desktop Entry]
Version=2018a
Type=Application
Terminal=false
MimeType=text/x-matlab
Exec=matlab -desktop -nosplash
Name=MATLAB
Icon=matlab
Categories=Development;Math;Science
Comment=Scientific computing environment
StartupNotify=true

If one need to set environment variable, one could prepend env in Exec, for example, to system's libfreetype:

Exec=env LD_PRELOAD=/usr/lib/libfreetype.so.6 matlab

One might wanna use system's libstdc++.

Installing from the AUR package

The EULA for the proprietary MATLAB software is restrictive. The matlabAUR package from the AUR is designed to allow MATLAB to be integrated into and managed by Arch. The package should be built on the system on which it is going to be installed and the package should be deleted from the installation location and the Pacman cache following installation. Distributing the package is a clear violation of the EULA.

The matlabAUR package from the AUR defaults to building a package for the most recent 64-bit release of MATLAB, one could also install old releases, eg. matlab-r2015bAUR. The matlabAUR package from the AUR requires that both the MATLAB installation software and the file installation key are available in the source directory.

In order to install Matlab from AUR, download the PKGBUILD file from AUR. Download the zip file containing the Matlab installer and name it matlab.zip. Then download the .lic file: Go in your MathWorks account and click on the license number you want to use. Then, go to the Install and Activate tab and select "Activate to Retrieve License File". Follow the instructions and download the license file needed for the installation and name the file matlab.lic. Also, the File Installation Key (FIK) is displayed: copy-paste it in a empty file and name it matlab.fik. For more details, refer to the PKGBUILD file.

Configuration

Java

The MATLAB software is bundled with a JVM and therefore it is not necessary to install Java. The JVM version supported by MATLAB is listed in System Requirements & Platform Availability or simply type version -java in MATLAB. One could set the MATLAB_JAVA environment variable to use custom JVM, for example, to specify the jre8-openjdk JRE, launch MATLAB with:

$ env MATLAB_JAVA=/usr/lib/jvm/java-8-openjdk/jre matlab

OpenGL acceleration

MATLAB can take advantage of hardware based 2D and 3D OpenGL acceleration. Support for hardware acceleration needs to be configured outside of MATLAB. Appropriate video drivers need to be installed along with the OpenGL utility library glu package. If X11 forwarding is being used, the video drivers need to be installed on both the client and server. To check if MATLAB is making use of hardware based OpenGL acceleration run:

$ matlab -nodesktop -nosplash -r "opengl info; exit" | grep Software

If "software rendering" is not "false", then there is a problem with your hardware acceleration. If this is the case make sure OpenGL is configured correctly on the system. This can be done with the glxinfo program from the mesa-demos package:

$ glxinfo | grep "direct rendering"

If "direct rendering" is not "yes", then there is likely a problem with your system configuration.

If glxinfo works but not matlab, you can try to run:

$ export LD_PRELOAD=/usr/lib/libstdc++.so; export LD_LIBRARY_PATH=/usr/lib/xorg/modules/dri/; matlab -nodesktop -nosplash -r "opengl info; exit" | grep Software

If its works, you can edit Matlab launcher script to add:

export LD_PRELOAD=/usr/lib/libstdc++.so
export LD_LIBRARY_PATH=/usr/lib/xorg/modules/dri/

Sound

To confirm that MATLAB is able to use the default soundcard to present sounds run:

$ matlab -nodesktop -nosplash -r "load handel; sound(y, Fs); pause(length(y)/Fs); exit" > /dev/null

This should play an except from Handel's "Hallelujah Chorus." If this fails make sure ALSA is properly configured. This can be done with the speaker-test program from the alsa-utils package from the official repositories:

$ speaker-test

If you do not hear anything, then there is likely a problem with your system configuration.

GPU computing

MATLAB can take advantage of CUDA enabled GPUs to speed up applications. In order to take advantage of a supported GPU install the nvidia, nvidia-utils, ocl-icd, opencl-nvidia, and cuda packages from the official repositories. To check if MATLAB is able to utilize the GPU run:

$ matlab -nodesktop -nosplash -r "x=rand(10, 'single'); g=gpuArray(x); Success=isequal(gather(g), x), exit"  | sed -ne '/Success =/,$p'

Install supported compilers

In order to access the full functionality of MATLAB (e.g., to use Simulink, Builder JA, and MEX-file compilation), supported versions of the gcc, g++, gfortran, and jdk compilers must be installed. Details about the supported compilers for the current release and previous releases are available online. Many of the supported gcc, g++, jdk compiler versions for past MATLAB releases are available from the AUR (e.g., gcc43AUR, gcc44AUR, gcc47AUR, gcc49AURand jdk6AUR), while past versions of the gfortran compilers are not packaged.

To use previous versions of the the gcc, g++, and gfortran compilers with MEX files, edit ${MATLAB}/bin/mexopts.sh and replace all occurrences of CC='gcc' with CC='gcc-4.X', CXX='g++' with CXX='g++-4.X', and FC='gfortran' with FC='gfortran-4.X', where X is the compiler version appropriate for the particular MATLAB release.

Note: Newer versions of Matlab (at least 2017a) doesn't seem to respect the ${MATLAB}/bin/mexopts.sh customization. Instead it uses ${MATLAB}/bin/glnxa64/mexopts/LANG_glnxa64.xml file.
Note: Though, it's no officially supported, one could still use higher version of compiler, and ignore the warnings.

Help browser

The help browser uses valuable slots in the dynamic thread vector and causes competition with core functionality provided by libraries like the BLAS that also depend on the dynamic thread vector. The help browser can be configured to use fewer slots in the dynamic thread vector with

>> webutils.htmlrenderer('basic');

This is a persistent change and to reverse it use

>> webutils.htmlrenderer('default');

Garbled Interface

export J2D_D3D=false
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre

Troubleshooting

Static TLS errors

MATLAB has a number of libraries that have been compiled with static thread local storage (TLS) including the help broswer doc and the BLAS libraries. For example,

>> doc('help');
>> ones(10)*randn(10);
Error using  * 
BLAS loading error:
dlopen: cannot load any more object with static TLS

is related to the bugs:

A more general solution of recompiling glibc has also been suggested. [2]

MATLAB crashes when displaying graphics

To identify this error, start MATLAB with

LIBGL_DEBUG=verbose matlab

from the terminal and try to collect OpenGL information with opengl info from the MATLAB command prompt. If it crashes again and there is an output line like

libGL error: dlopen /usr/lib/xorg/modules/dri/swrast_dri.so failed 
(/usr/local/MATLAB/R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: 
version `GLIBCXX_3.4.15' not found (required by /usr/lib/xorg/modules/dri/swrast_dri.so))

then the problem is that MATLAB uses its own GNU C++ library, which is an older version than the up-to-date version on your Archlinux system. Make MATLAB use the current C++ library for your system by

cd /usr/local/MATLAB/R(your release)/sys/os/glnxa64
sudo unlink libstdc++.so.6
sudo ln -s /usr/lib/libstdc++.so.6

If MATLAB still crashes or corrupts graphics (during startup or when plotting), make sure Java's 2D OpenGL rendering is disabled. The environment variable _JAVA_OPTIONS should not contain -Dsun.java2d.opengl=true.

Blank/grey UI when using WM (non-reparenting window manager)

This is a common issue in a number of window managers. (DWM, Awesome, bspwm) Java does not play well with these window managers. There are two methods.

First try setting the environment variable by running

$ export _JAVA_AWT_WM_NONREPARENTING=1

If Matlab works afterwards, export the variable in your .xinitrc.

If it doesn't resolve, you have to fool Java into thinking the WM is named LG3D. (It's an old, depreciated WM that Java applications ironically support) Clean the previous environment variable, install the wmname utility, and run.

wmname LG3D

Try running Matlab. If it works, put the fix in your starting script. (.xinitrc, bspwmrc and similar should be OK) Do note that other applications (such as neofetch, or tdrop) will think your WM is named LG3D, so you will have to configure them accordingly. Another solution is to run the command only before launching Matlab, and fixing the name after you are done with Matlab.

If it doesn't work, try the combination of both. (The second line works in bspwm) If it still doesn't work, try googling similar issues with java in general.

Garbled or invisible text

Set the environment variable J2D_D3D to false[3].

In newer versions of MATLAB (R2015b) [4] this also requires setting MATLAB_JAVA to something openjdk based. Example:

export J2D_D3D=false
./bin/glnxa64/install_unix -javadir /usr/lib/jvm/java-7-openjdk/jre

Corrupted text and fonts in menus and fields

If you notice that the menus or the input fields are corrupted or not appearing correctly then you can try to activate the "Use antialiasing to smooth desktop fonts" option in Matlab preferences, it seems to solve the problem. Go to Preferences -> Matlab -> Fonts and activate it. You will need to restart Matlab in order to take affect.

Installation

As one installs Matlab, it might complain that it cannot find a package, for the most part just look at the package name and then install it with Pacman, or in the case of x86_64 there are some libraries only in AUR.

Install-time library errors

  • Make sure that the symlink bin/glnx64/libstdc++.so.6 is pointing to the correct version of libstdc++.so.xx (which is also in the same directory and has numbers where 'xx' is). By default, it may be pointing to an older (and nonexistent) version (different value for 'xx').
  • Make sure the device you're installing from is not mounted as noexec
  • If you downloaded the files from Mathworks' website, make sure they are not on an NTFS or FAT partition, because that can mess up the symlinks. Ext4 or Ext3 should work.

Resolving start warnings/errors

  • Even if all needed libraries are installed, Matlab when starting can still report some missing libraries. This is resolved by symbolic linking of needed libraries to directories that Matlab checks at start-up. For example, if Matlab triggers error/warning about missing /lib64/libc.so.6 library, this can be resolved by:
# ln -s /lib/libc.so.6 /lib64
  • Matlab R2011b with an up-to-date Arch Linux (as of March 12, 2012) fails on startup with the familiar "Failure loading desktop class." A solution is to point Matlab to the system JVM (confirmed to work with the jdk7-openjdk package):
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre
  • Matlab R2017b with an up-to-date Arch Linux (as of September 30, 2017) fails on startup with the familiar "Failure loading desktop class." A solution is to install outdated versions of the libraries in the packages cairo (1.14.10 works) and harfbuzz (1.4.6 works) to a local directory and add them to the LD_LIBRARY_PATH for matlab (See also: [5]):
LD_LIBRARY_PATH="/opt/matlab/outdatedLibraries/:$LD_LIBRARY_PATH" /opt/matlab/R2017b/bin/matlab

Segmentation fault on startup

If Matlab (R2016a or earlier) stops working after upgrading ncurses to v6.x, install the ncurses5-compat-libsAUR package. See BBS#202575.

In newer versions (e.g. R2017b), the issue could also be due to a font display failing to load. Try moving the libfreetype.so.6 font display file in $MATLAB/bin/glnxa64/ to an 'exclude' directory; see BBS#231299.

ncurses compatibility layer is not required anymore for R2018a.

Hangs on rendering or exiting with Intel graphics

Some users have reported issues with DRI3 enabled on Intel Graphics chips. A possible workaround is to disable DRI3 and run MATLAB with hardware rendering on DRI2; to do so, launch MATLAB with the environment variable LIBGL_DRI3_DISABLE set to 1:

LIBGL_DRI3_DISABLE=1 /{MATLAB}/bin/matlab

If the previous workaround does not work, the issue can be circumvented by selecting software rendering with the MATLAB command (beware, performance may be very poor when doing e.g. big or complex 3D plots):

opengl('save','software')

See [6] and [7] for more.

Addon manager not working

This section is relevant for both R2017b and R2018a.

Addon manager requires the libselinuxAUR package to work.

Since upgrade from pango-1.40.5 to pango-1.40.6, the MATLABWindow application (responsible for Add-On Manager, Simulation Data Inspector and perhaps something else) cannot be started. [8] A workaround is to point MATLAB shipping glib libraries to those glib libraries from your system. There are 5 of those libraries in matlabroot/R2017b/cefclient/sys/os/glnxa64, namely, as of R2017b:

libgio-2.0.so
libglib-2.0.so
libgmodule-2.0.so
libgobject-2.0.so
libgthread-2.0.so

Make it so that these symlinks are pointing to your system glib libraries instead of versions located in matlabroot/R2017b/cefclient/sys/os/glnxa64. On a standard arch install the local files reside in /usr/lib/.

Do not forget to update the *.0 links as well.

Relinking of "libfreetype.so.6" is also necessary to open these interfaces. This is found in matlabroot/R2017b/bin/glnxa64/.

If the window opens but is blank, consider switching the html renderer to: " webutils.htmlrenderer('basic');" as described in #Help browser.

Live Script Errors

If you get the error when attempting to load or create a LiveScript:

 Viewing matlab live script files is not currently supported by this operating system configuration
  • It could be because of broken symlinks of libgcrypt and other dependencies, after system updates. On the first start of the Live Editor the components are extracted and these libary symlinks are created (if not existing). A solution is to simply delete the whole folder containing the broken symlinks and the extracted components, which are in the installation directory (represented by $MATLABROOT) under:
$MATLABROOT/sys/jxbrowser-chromium

Or if the installation directory is not user writable in:

~/.matlab/R2017b/HtmlPanel

Matlab will then regenerate the contents on the next Live Editor start.

>> com.mathworks.mde.liveeditor.widget.rtc.CachedLightweightBrowserFactory.createLightweightBrowser()

to get a more detailed error message.

  • A debugging console can be opened with
>> com.mathworks.mde.webbrowser.HtmlPanelDebugConsole.invoke;

Using webcam/video device

Make sure the correct support package addons are installed (webcam or OS Generic Video Interface for example). If running matlab as a user, make sure your user has write permissions to wherever the support packages are being downloaded and installed.

At least Matlab 2016b doesn't recognize webcams or imaq adapters correctly without gstreamer0.10. The gstreamer0.10 can be found in the aur and installed as a work around.

Since MATLAB R2017a, Image Acqusition Toolbox is using GStreamer library version 1.0. It previously used version 0.10.

In general, USB Webcam Support Package does a better job working with UVC and built-in cameras than OS Generic Video Interface Support Package.

Warning: As of 2018-08-15 updating gst from 1.14.0 to 1.14.2 breaks video device operation (MATLAB doesn't see the video device anymore). Downgrading fixes this.

MATLAB hangs for several minutes when closing Help Browser

Since upgrade of glibc from 2.24 to 2.25, MATLAB (at least R2017a) hangs when closing Help Browser. The issue is related to the particular version of jxbrowser-chromium shipped with MATLAB. This issue is still present with glibc 2.26 and MATLAB R2017b and R2018a.

To fix this issue, download the latest jxbrowser and replace the following jars from MATLAB:

matlabroot/java/jarext/jxbrowser-chromium/jxbrowser-chromium.jar
matlabroot/java/jarext/jxbrowser-chromium/jxbrowser-linux64.jar

MATLAB should automatically unpack those jars into matlabroot/sys/jxbrowser-chromium/glnxa64/chromium when first opening Help Browser. Remove matlabroot/sys/jxbrowser-chromium/glnxa64/chromium directory to make sure MATLAB uses the latest jxbrowser.

Unfortunately, this workaround doesn't work in R2017b anymore. Going deeper into investigation of this issue, it is related to a crash of one of jxbrowser-chromium processes. The parent process of jxbrowser-chromium then sits there and waits for response from a process that is already dead. This causes MATLAB main window to freeze. You can easily unfreeze MATLAB by manually killing all leftover jxbrowser-chromium processes.

I've come up with this simple script that uses inotify and waits for user to close Help browser in MATLAB. It triggers when user closes Help browser and sends kill signal to all leftover jxbrowser-chromium processes:

#!/usr/bin/bash

if [ -z "$1" ]; then
	REL=R2017b
else
	REL=$1
fi

JXPATH="/path/to/MATLAB/$REL/sys/jxbrowser-chromium/glnxa64/chromium"
CMD="inotifywait -m -e CLOSE $JXPATH/resources.pak"

#Exit if the daemon is already active
if ! pgrep -f "$CMD" > /dev/null; then
	#Wait for user to close Help Browser, then killall leftover jxbrowser processes
	$CMD |
	while read line
	do
		killall "$JXPATH/jxbrowser-chromium"
	done
else
	exit
fi

I run this script as part of my MATLAB start script like that:

~/bin/unfreeze_matlab.sh R2017b &

To make sure that this background job is killed when I exit MATLAB, I use this in the beginning of MATLAB start script:

trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT

Some dropdown menus cannot be selected

In some interfaces - such as Simulation Data Inspector or Simulink Test Manager - nothing happens when choosing an item in dropdown menu (for example, when trying to change a number of subplots in Simulation Data Inspector). To work around this issue, hold down the Shift key while clicking the item in dropdown menu.

Not starting - licensing error

In case MATLAB will not start from a desktop environment by the call of its desktop file one should see the output as you start it from the terminal.

For a Licensing error such as:

# matlab
MATLAB is selecting SOFTWARE OPENGL rendering.
License checkout failed.
License Manager Error -9
This error may occur when: 
-The hostid of this computer does not match the hostid in the license file. 
-A Designated Computer installation is in use by another user. 
If no other user is currently running MATLAB, you may need to activate.

Troubleshoot this issue by visiting: 
http://www.mathworks.com/support/lme/R2017a/9

Diagnostic Information:
Feature: MATLAB 
License path: /home/<USER>/.matlab/R2017a_licenses/license_<NUM>_R2017a.lic:/home/<USER>/.matlab/R2017a_licenses/lice
nse_Darkness_<NUM>_R2017a.lic:/opt/MATLAB/R2017a/licenses/license.dat:/opt/MATLAB/R2017a/licenses/*
.lic 
Licensing error: -9,57.

A re-activation might solve the problem.

MATLAB crashes with "Failure loading desktop class" on startup

In case MATLAB won't start and starting it from command line gives you the following error:

$ matlab
Fatal Internal Error: Internal Error: Failure occurs during desktop startup. Details: Failure loading desktop class.

and you have the option -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel set in your _JAVA_OPTIONS environment variable, start MATLAB with

$ _JAVA_OPTIONS= matlab

If this works, add the line

export _JAVA_OPTIONS=

to your MATLAB launcher script. Optionally re-add other Java options.

Unable to type in text fields of interfaces based on MATLABWindow

Since R2018a, it is not possible to type text in interfaces based on MATLABWindow - like Signal Editor, Add-Ons Explorer and others. MATLABWindow and MATLAB's webwindow infrastructure is based on Chromium Embedded Framework, and it looks like a known and long standing bug: https://bitbucket.org/chromiumembedded/cef/issues/2026/multiple-major-keyboard-focus-issues-on

One possible workaround is to switch focus from the MATLABWindow to another window and then switch back - so that you can type.

Matlab in a systemd-nspawn

Matlab can be run within a systemd-nspawn container to maintain a static system and avoid the library issues that often plague matlab installs after significant updates to libraries in Arch. Refer to Systemd-nspawn for detailed information on setting up such containers.

The following lists instruction to get a MATLAB 2017b install running in a minimal debian 9 environment. It assumes matlab is already installed as normal in "/usr/local/MATLAB/R2017b".

Use Xhost to allow the nspawn environment to use the existing X server instance.

Create a minimal debian environment in a folder ("deb9" here) with:

$ debootstrap --arch=amd64 stretch deb9

Set a password for the root user and then boot the environment with:

$ systemd-nspawn --bind-ro=/dev/dri --bind=/tmp/.X11-unix --bind=/usr/local/MATLAB/ -b -D deb9

Install the following packages to have the requisite libraries in the nspawn environment for MATLAB. "mesa-utils" and "usbutils" can be installed to debug graphics acceleration and usb interfaces for I/O with MATLAB.

$ apt-get install xorg build-essential libgtk2.0-0 libnss3 libasound2 

Install the MATLAB-support (from contrib source) package in the environment for some convenient integration.

$ apt-get install matlab-support

Set the $DISPLAY variable to use your existing X server instance.

$ export DISPLAY=:0

MATLAB can be launched from within the environment normally by using the binary at $MATLABROOT/bin.