ChronoEngine:Unit Matlab

From ChronoWiki

Jump to: navigation, search




Build depends:


Run depends:


Main developers:

Alessandro Tasora

This is an optional unit that can expand the features of the Chrono::Engine library. Read the introduction to units for a technical background on the modularity of the Chrono::Engine project.

This is a simple unit that allows exchanging matrices and variables from/to the Matlab environment with simple C++ function calls in Chrono::Engine.


The Matlab unit is used to provide an easy way to call Matlab functions from your Chrono::Engine -based application. Basically, you can

  • call Matlab commands from your C++ program,
  • send/retrieve data to/from Matlab (the Chrono::Engine C++ matrices are converted to Matlab, and viceversa)
  • use the Matlab powerful visualization tools, to show simulation data in 2D/3D plots, etc.

Planned, for the future, will be also an easy way to perform Simulink-Chrono::Engine cosimulation.


  • To run applications based on this unit:
    • you must have a licensed copy of Matlab(TM) installed on your system. We tested it from the 2006 revision up to the most recent.
    • your PATH environment variable must contain the path to the libeng.dll (see below)
  • To build applications based on this unit:
    • you must have a licensed copy of Matlab(TM) installed on your system. We tested it from the 2006 revision up to the most recent.

Building instructions

Currently this unit (differently from most others) does not correspond to an additional DLL library: it is a simple set of functions included in .h c++ headers. Therefore you do not need to build it.

However, when you build applications that use these headers, you must specify where you have the Matlab API/SDK installed on your system. For example, Matlab-based demos can be built if you enable them in the CMake window.

  • Repeat the instructions for the full installation, but when you see the CMake window, you must add the following steps:
  • Set the ENABLE_UNIT_MATLAB as 'on', then press 'Configure' (to refresh the variable list)
  • Set the CH_MATLAB_SDK to the path where you have your Matlab '/extern' subdirectory. This changes depending on where you installed Matlab. For example, it could be C:/Programmi/MATLAB/R2009b/extern
  • Press 'Configure' again, then 'Generate', and proceed as usual in the installation instructions.

When you will rebuild the project, you will find some Matlab-based demos in the binary directory. See the matlab tutorials for informations.

In most cases, when you run an executable that uses the Matlab unit, you will get an error message from Windows, telling that the libeng.dll library cannot be found. This means that you must tell Windows the path where to find it; so you need to modify the PATH system variable. Do the following:

  • Open your Matlab editor, type
[matlabroot '\bin\win32']

(or [matlabroot '\bin\win64'] on a 64 bit platform). You get the path to the dll on your system.

  • To set an environment variable in a Windows system, select Start > Settings > Control Panel > System. The System Properties dialog box is displayed. Click the Advanced tab, and then the Environment Variables button. In the System variables panel scroll down until you find the Path variable. Click this variable to highlight it, and then click the Edit button to open the Edit System Variable dialog box. At the end of the path string, enter a semicolon and then the path string returned by evaluating the expression shown above in MATLAB. Click OK in the Edit System Variable dialog box, and in all remaining dialog boxes.
Personal tools