# TOMLAB  
# REGISTER (TOMLAB)
# LOGIN  
# myTOMLAB
TOMLAB LOGO

« Previous « Start » Next »

9  Calling TOMLAB using MATLAB Engine

This section describes an example of calling TOMLAB using the MATLAB Engine from a stand alone application written i C.

9.1  The MATLAB Engine and TOMLAB

A stand alone application can utilize the MATLAB Engine API to literally start a MATLAB session and run commands in it as if it was a normal MATLAB session. The application can also create MATLAB data structures and put to the workspace of the MATLAB Engine workspace.

One can use the MATLAB Engine to call TOMLAB if one wants to be able to use the TOMLAB functionality as if it was run from MATLAB directly. For example, one advantage of the MATLAB Engine is when upgrading TOMLAB. Then your applications will use the upgraded version of TOMLAB without the need of recompiling the application. A drawback with the MATLAB Engine is that a MATLAB session requires much memory and takes more time to start than a compiled stand alone TOMLAB solution.

Calling TOMLAB and MATLAB using the MATLAB Engine doesn't require a TOMLAB stand alone license (TOMLAB SAL) or a MATLAB compiler license.

9.2  Compiling the example

In the TOMLAB distribution in directory: /examples/sal/engine there is an example of how to call TOMLAB using the MATLAB Engine.

On Windows make sure you have set the PATH environment properly according to the section: Building the example -> Setting paths in the README file in /examples/sal/engine. If you are using Microsoft Visual Studio C++ then call exmake.bat. If you are using another compiler then you could need to change the name of MATLAB compiler options file in exmake.bat. Some compilers need special treatment with floating point exception handling. See the MATLAB help for more information on this. The command line for compiling this stand alone application using the MATLAB Engine looks like this:
> mex -f <engine options file> tomeng.c
where <engine options file> is the options file to use for the compiler used by mex. In case of Microsoft Studio Visual C++ it is: <matlabroot>\bin\win32\mexopts\msvc50engmatopts.bat

On Unix make sure dynamic library path is set according to the section: Building the example -> Setting paths in the README file in /examples/sal/engine. Then call exmake.sh to compile the application. The command line for compiling a stand alone application under Unix looks exactly as it does for Windows, but the <engine options file> is: <matlabroot>/bin/engopts.sh instead.

9.3  Running the example

The example application sets up a QP problem by passing data to the MATLAB Engine workspace from the C part of the application. Then it uses a TOMLAB assign routine to create a TOMLAB representation of the problem and solves it using an arbitrary solver, chosen by the user.

The executable created when compiling the application should be called with two arguments:
> tomeng <tomlab directory> <TOMLAB QP solver name>
Assume TOMLAB is installed in c:\tomlab on a Windows system and /usr/local/tomlab on a Unix system and we want to use snopt to solve the problem, then the execution of tomeng would look like this respectively:
> tomeng c:\tomlab snopt
or
> ./tomeng /usr/local/tomlab snopt
If any of the steps during program execution fails it probably is because of an invalid TOMLAB installation at the chosen TOMLAB directory, an invalid TOMLAB license or a bad solver choice.

The source code of this example is situated in /examples/sal/engine/tomeng.c.

« Previous « Start » Next »