Difference between revisions of "Matlab"

From ArchWiki
Jump to: navigation, search
(Install 32-bit Matlab on 64-bit system)
(Installation)
 
(113 intermediate revisions by 31 users not shown)
Line 1: Line 1:
 
[[Category:Mathematics and science]]
 
[[Category:Mathematics and science]]
{{stub}}
+
[[ja:Matlab]]
 +
{{Related articles start}}
 +
{{Related|Octave}}
 +
{{Related|Sage-mathematics}}
 +
{{Related|Mathematica}}
 +
{{Related articles end}}
 +
{{Poor writing|unnecessarily verbose}}
 +
From the [http://www.mathworks.com/products/matlab/ official website]:
  
== General installation ==
+
:''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.''
  
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 {{Pkg|libxp}} is needed. You may need to [[Pacman|install]] {{Pkg|libxp}} from the [[official repositories]] first. Note also that Matlab is not compliant with Java 7, so you may need to install, for example, {{Pkg|openjdk6}}.
+
== Overview ==
Install from iso file:
+
# modprobe loop
+
# mount -o loop matlab.iso /mnt/
+
# /mnt/install
+
  
Additionally, install {{Pkg|xorg-fonts-100dpi}}, {{Pkg|xorg-fonts-75dpi}}, and {{Pkg|xorg-fonts-type1}} so fonts are displayed properly in figures.
+
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 (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted [http://www.mathworks.com/academia/students.html Student Version] which is released once a year. Since R2012b MATLAB has only been available for 64-bit Linux. While MATLAB is officially supported on a number of [http://www.mathworks.co.uk/support/sysreq/current_release/index.html?sec=linux Linux distributions], Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward.
 +
 
 +
== Installation ==
 +
 
 +
A complete copy of the MATLAB software must be obtained before it can in 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).
 +
 
 +
=== 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. 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.
 +
 
 +
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.
 +
 
 +
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:
  
=== Create Desktop and Menu Shortcuts ===
 
If you choose Custom in Installation Type, the symlink will be created automatically. Otherwise, you may need to manually create a symlink in {{ic|/usr/local/bin}} to make it easier to launch in terminal:
 
 
 
  # ln -s /{MATLAB}/bin/matlab /usr/local/bin
 
  # ln -s /{MATLAB}/bin/matlab /usr/local/bin
  
 
To create a menu item, we need to get a icon first:
 
To create a menu item, we need to get a icon first:
 
# wget http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -O /usr/share/icons/matlab.png
 
  
Then create a new .desktop file in {{ic|/usr/share/applications}} with following lines:
+
# curl https://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png
 +
 
 +
Then create a new {{ic|.desktop}} file in {{ic|/usr/share/applications}} with following lines:
  
 
{{hc|/usr/share/applications/matlab.desktop|<nowiki>
 
{{hc|/usr/share/applications/matlab.desktop|<nowiki>
Line 28: Line 40:
 
Type=Application
 
Type=Application
 
Icon=/usr/share/icons/matlab.png
 
Icon=/usr/share/icons/matlab.png
Name=MATLAB R2012a
+
Name=MATLAB
 
Comment=Start MATLAB - The Language of Technical Computing
 
Comment=Start MATLAB - The Language of Technical Computing
Exec=matlab -desktop
+
Exec=matlab -desktop -nosplash
 
Categories=Development;
 
Categories=Development;
 +
MimeType=text/x-matlab;
 +
StartupWMClass=sun-awt-X11-XFramePeer
 +
</nowiki>}}
 +
 +
The {{ic|Exec}} command line is composed as follows:
 +
 +
* {{ic|-desktop}} is a flag needed to run Matlab without a terminal.
 +
* {{ic|-nosplash}} is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.
 +
 +
You can also put this {{ic|.desktop}} file in the {{ic|~/Desktop}} directory to create a shortcut on your desktop. See also [https://help.ubuntu.com/community/MATLAB].
 +
 +
=== Installing from the AUR package ===
 +
 +
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.
 +
 +
The {{aur|matlab}} package from the [[AUR]] defaults to building a package for the most recent 64-bit release of MATLAB, although the PKGBUILD supports MATLAB releases from R2010b and even the installation of multiple releases simultaneous. The PKGBUILD defaults to installing all toolboxes that the file identification key allows, however, the PKGBUILD can be edited to include only a subset of the toolboxes. The selection of the toolboxes must be finalized at the time of package creation due to DRM policies put in place by The MathWorks. 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. The file installation key must be in a file called {{ic|matlab.fik}} and the installation software must be in an iso file called {{ic|matlab.iso}}. Once the iso file and file installation key are created, the MATLAB package can be created and install as usual.
 +
 +
For MATLAB releases between r2010b and r2011a the contents of the iso file must include: {{ic|./archives/}}, {{ic|./bin/}}, {{ic|./etc/}}, {{ic|./help/}}, {{ic|./java/}}, {{ic|./activate.ini}}, {{ic|./install}}, and {{ic|./installer_input.txt}}. If the MATLAB download agent is used to download the installation software, then the iso file can be trivially created by simply running {{ic|mkisofs -r -o}} on the download directory.
 +
 +
For MATLAB releases including and after r2011b the contents of the iso file must include: {{ic|./archives/}}, {{ic|./bin/}}, {{ic|./etc/}}, {{ic|./help/}}, {{ic|./java/}}, {{ic|./activate.ini}}, {{ic|./install}}, and {{ic|./installer_input.txt}}. For version before r2014a, the MATLAB download agent could download all the required files and the iso file could be trivially created by simply running {{ic|mkisofs -r -o}} on the download directory. For MATLAB releases including and after r2014a the MATLAB download agent only downloads the MATLAB installer. The MATLAB installer then needs to be run to downloaded the MATLAB software and toolboxes. Therefore, a two step process is required to generate this iso file with the MATLAB download agent. First, you download and run the MATLAB installer to install MATLAB in a temporary directory. This process downloads the MATLAB software and toolboxes by default to {{ic|~/Downloads/MathWorks}} (this can be changed by passing the flag {{ic|-downloadFolder /path/to/directory}}). It is actually possible quit the MATLAB installer once the software and toolboxes are downloaded. Once the software and toolboxes are downloaded the required iso file can be created by merging the installer directory (containing above mentioned files) and the download directory (containing {{ic|./archives/}}), and then running {{ic|mkisofs -r -o}} on the resulting directory.
 +
 +
== Activation ==
 +
 +
In order to run MATLAB it requires a license file to be installed. The license file can be generated with {{ic|$MATLABROOT/bin/activate_matlab.sh}} or downloaded from [http://www.mathworks.com MATLAB] directly.
 +
 +
=== R2013b and earlier ===
 +
 +
Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the [[Network_configuration#Device_names|Predictable Network Interface Names]] used by Arch Linux. It is possible to disable predictable network interface names by adding {{ic|1=net.ifnames=0}} in your kernel command line or by creating a udev rule file
 +
 +
{{bc|# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules}}
 +
 +
It is also possible to [[Network_configuration#Change_device_name|change the name of a device]], but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using {{ic|ip link}}. Next, create the following file:
 +
 +
{{hc|/etc/systemd/system/matlab.licensing.service|<nowiki>
 +
[Unit]
 +
Description=Dummy network interface for MATLAB
 +
Requires=systemd-modules-load.service
 +
 +
[Service]
 +
Type=oneshot
 +
ExecStart=/sbin/ip link set dev dummy0 name eth0
 +
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00
 +
 +
[Install]
 +
WantedBy=multi-user.target
 
</nowiki>
 
</nowiki>
 
}}
 
}}
  
You can also put this .desktop file in the Desktop folder to create a shortcut.
+
Replace 00:00:00:00:00:00 with the MAC address linked to the license file.
  
More details see [https://help.ubuntu.com/community/MATLAB MATLAB - Community Ubuntu Documents]
+
Then make the script run on boot:
  
=== Install 32-bit Matlab on 64-bit system ===
+
  # systemctl enable matlab.licensing
{{Out of date|Since Version R2012b all Linux versions are 64bit. That's not true for students versions!}}
+
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 r2012a student version. To start off with we need to install a bunch of lib32 packages, not all found with pacman. The following packages must be installed (the list may be out of date):
+
{{Pkg|lib32-mesa}}, {{Pkg|lib32-glu}}, {{Pkg|lib32-glibc}}, {{Pkg|lib32-libxmu}}, {{Pkg|lib32-zlib}}, {{Pkg|lib32-ncurses}}, {{Pkg|lib32-libxtst}}, {{Pkg|lib32-libxi}}, {{Pkg|lib32-libxrender}}, {{Pkg|lib32-libxfixes}}, {{Pkg|lib32-freetype2}}, {{Pkg|lib32-fontconfig}}, {{Pkg|lib32-libxdamage}} from the [[official repositories]] and {{AUR|lib32-libxpm}}, {{AUR|lib32-libxp}}, {{AUR|bin32-openjdk6}} (32 bit openjdk7 might also work) from the [[AUR]].
+
  
Once they are installed:  
+
Finally, set the dummy module to load on boot by creating the following file:
  
$ ./install -glnx86
+
{{hc|/etc/modules-load.d/dummy.conf|<nowiki>dummy</nowiki>}}
  
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 {{ic|${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:
+
== Configuration ==
  
$ cd ${MATLAB}/sys/java/jre
+
=== Java ===
$ ln -s glnx86 glnxa64
+
  
In the above, ${MATLAB} should be replaced by the root directory you chose for your installation.
+
The MATLAB software is bundled with a JVM and therefore it is not necessary to install [[Java]]. The JVM version bundled with MATLAB typically lags behind {{pkg|jre7-openjdk}} from the [[official repositories]] and it is possible, although not required, to use the {{ic|MATLAB_JAVA}} environment variable to specify the path of an alternative JRE. For example, to specify the {{pkg|jre7-openjdk}} JRE and check the resulting version of Java, do:
  
You'll also need to put another link in Matlab's {{ic|bin}} folder because despite asking Matlab to install the 32bit version, it still thinks you want to use the 64bit one:
+
{{bc|<nowiki>$ MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre matlab -nodesktop -nosplash -r "version -java, exit" | grep Java</nowiki>}}
  
$ cd ${MATLAB}/bin
+
Using alternative JRE would often solve some long-standing problems, such as the extra "{{ic|MEvent. CASE!}}" string when doing two-finger scrolling using touchpad. Another problem that can be solved in this way is the ugly, limited fonts provided by default, especially for some Chinese characters.
$ ln -s glnx86 glnxa64
+
  
After that you'll need to edit the {{ic|${MATLAB}/bin/matlab}} script to get the java settings correct.  After the comments at the top of the file, you'll need the line:
+
=== OpenGL acceleration ===
  
export MATLAB_JAVA=/path/to/jre
+
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 from the [[official repositories]]. 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:
  
Where {{ic|/path/to/jre}} will be {{ic|/opt/java/jre}} if you're using Sun's JRE.  The path is one level up from where {{ic|rt.jar}} is located.  That is, {{ic|rt.jar}} should be in {{ic|/opt/java/jre/libs}} if you used {{ic|/opt/java/jre}} for {{ic|MATLAB_JAVA}}. In Matlab R2010a it works pretty well, if you use the internal JRE with:
+
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "opengl info; exit" | grep Software</nowiki>}}
  
export MATLAB_JAVA=${MATLAB}/sys/java/jre/glnx86/jre
+
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 from the [[official repositories]]:
  
If using {{AUR|bin32-openjdk6}}, use
+
{{bc|<nowiki>$ glxinfo | grep "direct rendering"</nowiki>}}
  
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre/
+
If "direct rendering" is not "yes", then there is likely a problem with your system configuration.
  
To run it, you'll need to:
+
=== Fonts for figures ===
  
$ ${MATLAB}/bin/matlab -glnx86 -desktop
+
{{Note| This section only applies to R2014a and earlier as starting with R2014b MATLAB uses True Type Fonts.  So as long as:
 +
{{bc|<nowiki>$ fc-match Helvetica</nowiki>}}
 +
returns a font, figure fonts should work as expected.}}
  
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.
+
While MATLAB can be run in a text only mode, it also provides advanced graphics capabilities. To confirm that MATLAB is making use of the system fonts run:
  
=== Install supported compiler ===
+
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "xlabel('BIG FONT', 'FontSize', 42); ylabel('small font', 'FontSize', 12); pause; exit" > /dev/null</nowiki>}}
  
In order for Matlab to work with C code it is necessarry to install a supported Compiler. Install {{AUR|gcc44}} from the AUR.
+
This should produce a MATLAB figure with "BIG FONT" in a large font on the abscissa and "small font" in a small font on the ordinate. If "BIG FONT" and "small font" are both the same size, refer to [[Xorg#Program_requests_.22font_.27.28null.29.27.22|Xorg fonts]] to confirm that the correct the bitmap font package (either {{Pkg|xorg-fonts-100dpi}} or {{Pkg|xorg-fonts-75dpi}} from the [[official repositories]]) is installed on your system.
  
Then edit {{ic|${MATLAB}/bin/mexopts.sh}} and replace all occurances of CC='gcc' with CC='gcc-4.4' and CXX='g++' with CXX='g++-4.4'. Afterwards run
+
=== Sound ===
mex -setup
+
in Matlab and select the {{ic|mexopts.sh}} file.
+
  
== Troubleshooting ==
+
To confirm that MATLAB is able to use the default soundcard to present sounds run:
As one installs Matlab, it might complain that it can't 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]].
+
  
==== Resolving start warnings/errors ====
+
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "load handel; sound(y, Fs); pause(length(y)/Fs); exit" > /dev/null</nowiki>}}
  
* 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:
+
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]]:
  
# ln -s /lib/libc.so.6 /lib64
+
{{bc|<nowiki>$ speaker-test</nowiki>}}
  
* 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):
+
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:
 +
 
 +
{{bc|<nowiki>$ matlab -nodesktop -nosplash -r "x=rand(10, 'single'); g=gpuArray(x); Success=isequal(gather(g), x), exit" | sed -ne '/Success =/,$p'</nowiki>}}
 +
 
 +
=== 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 [http://www.mathworks.com/support/compilers/current_release/index.html?sec=glnxa64 current release] and [http://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}}, 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.
 +
 
 +
=== 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
  
==== MATLAB crashes when displaying graphics ====
+
== 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);
 +
<span style="color:red">
 +
Error using  *
 +
BLAS loading error:
 +
dlopen: cannot load any more object with static TLS
 +
</span>
 +
 
 +
is related to bugs [http://www.mathworks.de/support/bugreports/961964 961964] and [http://www.mathworks.com/support/bugreports/1003952 1003952]. In some cases (e.g., bug [http://www.mathworks.de/support/bugreports/961964 961964]) 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 The MathWorks], while in others (e.g., bug [http://www.mathworks.com/support/bugreports/1003952 1003952]) work arounds exist. A more general solution of recompiling {{ic|glibc}} has also been [http://stackoverflow.com/a/19468365/2787723 suggested].
 +
 
 +
=== MATLAB crashes when displaying graphics ===
  
 
To identify this error, start MATLAB with
 
To identify this error, start MATLAB with
Line 117: Line 209:
 
  sudo ln -s /usr/lib/libstdc++.so.6
 
  sudo ln -s /usr/lib/libstdc++.so.6
  
== OpenGL Acceleration ==
+
=== Blank/grey UI when using DWM/Awesome ===
  
Once Matlab is installed type the following in the interpreter:
+
[http://tools.suckless.org/wmname wmname] is a utility to set the window manager name of the root window.
  
  >> opengl info
+
  wmname LG3D
  
The output should be similar to the following:
+
Then start Matlab.
  
{{bc|<nowiki>
+
=== Garbled or invisible text ===
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:
+
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].
OpenGLBitmapZbufferBug    = 0
+
OpenGLWobbleTesselatorBug = 0
+
OpenGLLineSmoothingBug    = 0
+
OpenGLClippedImageBug    = 0
+
OpenGLEraseModeBug        = 0
+
</nowiki>}}
+
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 ===
+
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:
  
With an [[Nvidia|NVIDIA]] card, the output should be similar to this:
+
export J2D_D3D=false
{{bc|<nowiki>
+
./bin/glnxa64/install_unix -javadir /usr/lib/jvm/java-7-openjdk/jre
>> 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:
+
=== Corrupted text and fonts in menus and fields ===
OpenGLBitmapZbufferBug    = 0
+
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.
OpenGLWobbleTesselatorBug = 0
+
 
OpenGLLineSmoothingBug    = 0
+
=== Installation ===
OpenGLClippedImageBug    = 1
+
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]].
OpenGLEraseModeBug        = 0
+
 
</nowiki>}}
+
=== 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
  
With the NVIDIA card all it required to start working was to copy the {{ic|libGLU.so}} from the Matlab installed library {{ic|${MATLAB}/sys/opengl/lib/glnx86/libGLU.so}} to {{ic|/usr/lib directory}}. Note that in x86_64 this might be a different directory.
+
=== Segmentation Fault on startup ===
  
{{Note|Although, not thoroughly tested, using {{Pkg|lib32-nvidia-utils}} seems to work as well.}}
+
If Matlab 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].

Latest revision as of 17:31, 2 May 2016

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements.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 (generally in March and September) with release names of R20XXa and R20XXb. The MathWorks also provide a discounted Student Version which is released once a year. Since R2012b MATLAB has only been available for 64-bit Linux. While MATLAB is officially supported on a number of Linux distributions, Arch is not officially supported. Despite the lack of official support, installing and using MATLAB on Arch is straight forward.

Installation

A complete copy of the MATLAB software must be obtained before it can in 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. 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

To create a menu item, we need to get a icon first:

# curl https://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -o /usr/share/icons/matlab.png

Then create a new .desktop file in /usr/share/applications with following lines:

/usr/share/applications/matlab.desktop
#!/usr/bin/env xdg-open
[Desktop Entry]
Type=Application
Icon=/usr/share/icons/matlab.png
Name=MATLAB
Comment=Start MATLAB - The Language of Technical Computing
Exec=matlab -desktop -nosplash
Categories=Development;
MimeType=text/x-matlab;
StartupWMClass=sun-awt-X11-XFramePeer

The Exec command line is composed as follows:

  • -desktop is a flag needed to run Matlab without a terminal.
  • -nosplash is a flag preventing the splash screen from showing and taking up a temporary space in your task bar.

You can also put this .desktop file in the ~/Desktop directory to create a shortcut on your desktop. See also [1].

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, although the PKGBUILD supports MATLAB releases from R2010b and even the installation of multiple releases simultaneous. The PKGBUILD defaults to installing all toolboxes that the file identification key allows, however, the PKGBUILD can be edited to include only a subset of the toolboxes. The selection of the toolboxes must be finalized at the time of package creation due to DRM policies put in place by The MathWorks. The matlabAUR package from the AUR requires that both the MATLAB installation software and the file installation key are available in the source directory. The file installation key must be in a file called matlab.fik and the installation software must be in an iso file called matlab.iso. Once the iso file and file installation key are created, the MATLAB package can be created and install as usual.

For MATLAB releases between r2010b and r2011a the contents of the iso file must include: ./archives/, ./bin/, ./etc/, ./help/, ./java/, ./activate.ini, ./install, and ./installer_input.txt. If the MATLAB download agent is used to download the installation software, then the iso file can be trivially created by simply running mkisofs -r -o on the download directory.

For MATLAB releases including and after r2011b the contents of the iso file must include: ./archives/, ./bin/, ./etc/, ./help/, ./java/, ./activate.ini, ./install, and ./installer_input.txt. For version before r2014a, the MATLAB download agent could download all the required files and the iso file could be trivially created by simply running mkisofs -r -o on the download directory. For MATLAB releases including and after r2014a the MATLAB download agent only downloads the MATLAB installer. The MATLAB installer then needs to be run to downloaded the MATLAB software and toolboxes. Therefore, a two step process is required to generate this iso file with the MATLAB download agent. First, you download and run the MATLAB installer to install MATLAB in a temporary directory. This process downloads the MATLAB software and toolboxes by default to ~/Downloads/MathWorks (this can be changed by passing the flag -downloadFolder /path/to/directory). It is actually possible quit the MATLAB installer once the software and toolboxes are downloaded. Once the software and toolboxes are downloaded the required iso file can be created by merging the installer directory (containing above mentioned files) and the download directory (containing ./archives/), and then running mkisofs -r -o on the resulting directory.

Activation

In order to run MATLAB it requires a license file to be installed. The license file can be generated with $MATLABROOT/bin/activate_matlab.sh or downloaded from MATLAB directly.

R2013b and earlier

Up to and including R2013b the license file was linked to the MAC address of eth0. This causes problems with the Predictable Network Interface Names used by Arch Linux. It is possible to disable predictable network interface names by adding net.ifnames=0 in your kernel command line or by creating a udev rule file

# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules

It is also possible to change the name of a device, but changing the name to eth0 can result in race conditions between the kernel and udev during boot. Another solution is to create a dummy network interface named eth0 with the MAC address linked to the license file. First, get that MAC address using ip link. Next, create the following file:

/etc/systemd/system/matlab.licensing.service
[Unit]
Description=Dummy network interface for MATLAB
Requires=systemd-modules-load.service

[Service]
Type=oneshot
ExecStart=/sbin/ip link set dev dummy0 name eth0
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00

[Install]
WantedBy=multi-user.target

Replace 00:00:00:00:00:00 with the MAC address linked to the license file.

Then make the script run on boot:

# systemctl enable matlab.licensing

Finally, set the dummy module to load on boot by creating the following file:

/etc/modules-load.d/dummy.conf
dummy

Configuration

Java

The MATLAB software is bundled with a JVM and therefore it is not necessary to install Java. The JVM version bundled with MATLAB typically lags behind jre7-openjdk from the official repositories and it is possible, although not required, to use the MATLAB_JAVA environment variable to specify the path of an alternative JRE. For example, to specify the jre7-openjdk JRE and check the resulting version of Java, do:

$ MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre matlab -nodesktop -nosplash -r "version -java, exit" | grep Java

Using alternative JRE would often solve some long-standing problems, such as the extra "MEvent. CASE!" string when doing two-finger scrolling using touchpad. Another problem that can be solved in this way is the ugly, limited fonts provided by default, especially for some Chinese characters.

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 from the official repositories. 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 from the official repositories:

$ glxinfo | grep "direct rendering"

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

Fonts for figures

Note: This section only applies to R2014a and earlier as starting with R2014b MATLAB uses True Type Fonts. So as long as:
$ fc-match Helvetica
returns a font, figure fonts should work as expected.

While MATLAB can be run in a text only mode, it also provides advanced graphics capabilities. To confirm that MATLAB is making use of the system fonts run:

$ matlab -nodesktop -nosplash -r "xlabel('BIG FONT', 'FontSize', 42); ylabel('small font', 'FontSize', 12); pause; exit" > /dev/null

This should produce a MATLAB figure with "BIG FONT" in a large font on the abscissa and "small font" in a small font on the ordinate. If "BIG FONT" and "small font" are both the same size, refer to Xorg fonts to confirm that the correct the bitmap font package (either xorg-fonts-100dpi or xorg-fonts-75dpi from the official repositories) is installed on your system.

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, and 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.

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 bugs 961964 and 1003952. In some cases (e.g., bug 961964) patched libraries are available from The MathWorks, while in others (e.g., bug 1003952) work arounds exist. A more general solution of recompiling glibc has also been suggested.

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

Blank/grey UI when using DWM/Awesome

wmname is a utility to set the window manager name of the root window.

wmname LG3D

Then start Matlab.

Garbled or invisible text

Set the environment variable J2D_D3D to false[2].

In newer versions of MATLAB (R2015b) [3] 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

Segmentation Fault on startup

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