vsTASKER 7 Tutorial
×
Menu
Index

MATLAB

 
 
Matlab functions used in vsTASKER must be translated into C++ code and compiled with the MCC compiler of Matlab.
The compiler will produce a library that will gather all the Matlab functions defined in the database.
It is this library that will be linked with the vsTASKER libraries to produce the simulation engine.
 
Matlab must be installed on the computer in order to run a simulation engine with Matlab functions. This is because the library produced by the MCC compiler relies on Matlab DLL that will be loaded with the vsTASKER simulation engine.
 
Once Matlab is installed, define the following environment variable that will point to the directory.
For i.e: set MATLAB "D:\Program Files (x86)\MATLAB\R2011a"
 
Open the Tools::Preferences::MATLAB Settings (see User Manual for description) and check the installation.
 
 
First, setup MATLAB environment (see above) to reflect the installation. Use Win32 MATLAB libraries if you expect to build a x86 simulation engine and Win64 for x64 bits platform engine.
 
Now, let's create a simple function sqr (for square root).
 
Create the Matlab function:
 
 
Then, write the function itself:
 
 function y = sqr(a)
 y = a*a
 
and in the Interface panel, add the following:
 
 return y scalar
 a scalar
 
Finally, with the button, save the m-file as is:
 
D:\VirtualSim\vsTasker\7\Runtime\MATLAB\m-files\sqr.m
The directory (here \Runtime\MATLAB\m-files) must be the same as the one defined in the Matlab Settings for Functions (see below).
 
 
Now, create a Logic sqr_test and one Action sqr_display
In the Action, add the following code:
 
 printf("Sqr(5) = %f\n", m.sqr(5)); // m is the accessor of all Matlab functions of the database
 
Give the sqr_test Logic to the (Scenario) Player then compile (you will see that the Matlab compiler will be called - if Matlab correctly setup), link and produce a Sim Engine.
Load the simulation and run.
On the Console, you will see: Sqr(5) = 25