Revision 43 as of 2022-05-09 06:25:39

Clear message

Matlab

Matlab is a high-level language and interactive environment for numerical computation, visualization, and programming.

Start Matlab

First Steps

Matlab has a lot of tutorials by its own. You can find them in Matlab: Help - Product Help - User Guides

Matlab Compiler

How to use Matlab Compiler on Linux

This section shows an example on how to use MATLAB Compiler to code and build standalone applications.

Magic Square Example

A magic square is an array of integers arranged so that their sum is the same when added vertically, horizontally, or diagonally. Copy the following code in a text-file and save it as magicsquare.m:

function m = magicsquare(n)
%MAGICSQUARE generates a magic square matrix of the size
% specified by the input parameter n.
% Copyright 2003-2011 The MathWorks, Inc.

if ischar(n)
    n=str2num(n);
end
m = magic(n);
m

Important: When this program is executed in a Linux terminal, we have to use the function str2num (string to number). Arguments are used as strings, that's why they have to be converted into a number in Matlab.

Compile the magicsquare function (with the command: mcc) in a Linux terminal.

To run the magicsquare program we give the shell script two arguments. The first is the path to the Matlab Compiler Runtime. The second argument in this example is an application-specific param for the program magicsquare itself. Important: The version of the compiler Runtime needs to be same that was used by the compiler mcc.

> ./run_magicsquare.sh /usr/pack/matlab-2021b-fg 5
------------------------------------------
Setting up environment variables
---
LD_LIBRARY_PATH is .:/usr/pack/matlab-2021b-fg/runtime/glnxa64:/usr/pack/matlab-2021b-fg/bin/glnxa64:/usr/pack/matlab-2021b-fg/sys/os/glnxa64:/usr/pack/matlab-2021b-fg/sys/opengl/lib/glnxa64

m =

    17    24     1     8    15
    23     5     7    14    16
     4     6    13    20    22
    10    12    19    21     3
    11    18    25     2     9

More help on mcc: Enter on commandline: mcc -help

Or see the Matlab-Documentation in Matlab: Help - Product Help - Matlab Compiler

Matlab on the cluster (Condor, Slurm)

Limited amount of MATLAB licenses

The number of MATLAB licenses is limited. To ensure a fair and efficient usage of the (site-)licenses throughout the ETH, the following measures have been put in place:

How to avoid allocating too many MATLAB licenses?

  1. Compile your MATLAB program. The best approach to avoid excessive usage of MATLAB licenses is to compile your MATLAB program. The resulting executable does not need ANY MATLAB licenses! This frees you from all MATLAB license restrictions and also allows you to provide your executable to users without a MATLAB installation.

  2. Exit MATLAB after finishing your work. Only exiting matlab will really release all allocated licenses.

  3. Announce the need for many MATLAB licenses, e.g. due to a MATLAB course, by registering your need in advance. Countermeasures can be taken in this case by the IT department which ensure that the requested amount of licenses will available. Use the IDES contact form therefore: https://idts.ethz.ch/hdweb/ (Nethz-login required)

  4. Buy your own MATLAB licenses if you must have a guaranteed 24/7 license availability or if you need constantly an excessive amount of licenses.

How do I know which MATLAB licenses I use?

How do I know how many MATLAB licenses are used by whom?


CategoryBTCH