domatlab

Navigation:  Language Reference > Statements >

domatlab

Previous pageReturn to chapter overviewNext page

Syntax

doMatlab('string')

Description

The doMatlab statement allows you to pass a command line string to Matlab.

Example

// this example shows how a variable can be transferred to matlab and from matlab during simulation

variables

 real x;

 real y;

 real vector[2];

 real matrix[2,2];

 

// at the start of the simulation

initialequations

 // create an empty array a

 doMatlab ('a = []; ');

 // create a variable

 doMatlab ('b=0; ');

 // create a vector

 doMatlab ('vector=[1 2];');

 // create a matrix

 doMatlab ('matrix=[1 2; 3 4];');

 

// during simulation

equations

 // calculate x

 x = sin (time);

 // send it to Matlab

 toMatlab (x,'x');

 // and add it to array a

 doMatlab ('a = [ a x ]; ');

 // in Matlab add 2 to x

 doMatlab ('b = x + 2;');

 // read matlab 'b' into 20-sim variable 'y'

 fromMatlab(y, 'b');

 // read matlab 'vector' into 20-sim variable 'vector'

 fromMatlab(vector, 'vector');

 // read matlab 'matrix' into 20-sim variable 'matrix'

 fromMatlab(matrix, 'matrix');

 

// at the end of the simulation

finalequations

 // plot the resulting array in Matlab

 doMatlab (' plot (a); ');