Install the MATLAB module

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

Read the introduction to modules for a technical background on the modularity of the Chrono::Engine project.

Features

The Matlab module 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.

Requirements

  • To run applications based on this module:
    • 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 module:
    • 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

  1. Repeat the instructions for the full installation, but when you see the CMake window, you must add the following steps:
  2. Set the ENABLE_MODULE_MATLAB as 'on', then press 'Configure' (to refresh the variable list)
  3. 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:/Program Files/MATLAB/R2015b/extern
  4. Press 'Configure' again, then 'Generate', and proceed as usual in the installation instructions.
In most cases, when you run an executable that uses the Matlab module, 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:

1.Open your Matlab editor, type
[matlabroot "\bin\win64"]
(or [matlabroot "\bin\win32"] on a 32 bit platform). You get the path to the dll on your system.

2.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.
In some cases, in Windows, the Matlab engine cannot be started because it was not registered in COM during its installation. In this case, when launching the "demo_matlab.exe", you get a message like "Can't start MATLAB engine". To fix this problem:

1.Open your Matlab editor,
2.type !matlab -regserver

How to use it

  • Look at the API section of this module for documentation about classes and functions.
  • Look at the C++ source of demos to learn how to use the functions of this module.