Contents - Index

Calling EES from MATLAB


Shown below is a small MATLAB M file called EES_MATLAB.m that plays an EES Macro fileAn alternative way to have EES and MATLAB interact is by using the /solve parameter or to use the MATLAB system command


% This file shows how EES and MATLAB can be coupled through file transfer

%% First start a DDE conversation between MATLAB and EES

chan = ddeinit('EES','DDE');

% Now let EES load the EES file 

rc = ddeexec(chan,'[Open EES_MATLab.ees]');  % Alternative rc = ddeexec(chan,'Play EES_MATLab.emf');



% Create a File in MATLAB such that it can be read by EES with the $Import directive

var1 = 1;

var2 = 2;

var3 = 3;

var4 = 4;

var5 = 5;

t = 0;

for i = 1:10 

  t = t + 1

  save MatLabInput.txt var1 var2 var3 var4 var5 t -ascii 

  % Ask EES solve the previously loaded program

  rc = ddeexec(chan,'[Solve]');

  % Read a file created by EES through the $EXPORT command into MATLAB

  erg = csvread('EESOutput.csv'



% Terminate the DDE conversation between MATLAB and EES




The EES file called by MATLAB is as follows:



$Import 'C:\ees32\ees_MATLAB\MatLabInput.txt',  var1, var2, var3, var4, var5, t

erg = (var1 + var2 + var3 + var4 + var5) * t

$Export 'C:\ees32\ees_MATLAB\EESOutput.csv', erg



Note that, as an alternative to opening and solving an EES file as demonstrated  here, it may be simpler to Play a macro file.  This would be accomplished with the following command from MATLAB


rc = ddeexec(chan,'Play EES_MATLAB.emf')


where EES_MATLAB.emf is an EES macro file containing the list of EES commands that are to be run.


Place the EES_MATLAB.m and EES_MATLAB.EES files in the C:\EES32\EES_MATLAB directory.  In order to run this macro from MATLAB, EES must be running in the background so start EES and then minimize it.  Start MATLAB and enter the following commands





The Professional version of EES is required to run these examples.


See also:

  Executing an EES Macro File from MATLAB