Programming and Graphics

(Kiana) #1

292 Introduction to C++ Programming and Graphics


engOutputBuffer (ep, Bufname, Bufsize);

whereBufsizeandBugnameare given names. The functionengOutputBuffer
returns an integer.


Executing aMatlabcommand


We can execute (evaluate) aMatlabcommand directly by invoking the
function:


engEvalString (ep, "matlab command");

or indirectly by issuing the commands:


char mcom[] = "matlab command";
engEvalString (ep, mcom);

The functionengEvalStringreturns an integer.


Putting variables into theMatlabworkspace


We can transfer a variable from the C++ domain to the engine workspace
by invoking the function:


engPutVariable (Engine *ep, const char *string, const mxArray * string);

as discussed in Section 9.4. The functionengPutVariablereturns an integer.


Retrieving variables from theMatlabworkspace


We can transfer a variable from theMatlabworkspace to the C++
domain by invoking the function:


mxArray * engGetVariable (Engine *ep, const char *string);

as discussed in Section 9.5.


Running aMatlabsession


In the simplest application, we startMatlabfrom a C++ program and
carry out various computations in theMatlabworkspace. The commands
are transferred from the C++ domain to theMatlabworkspace, and the
Matlabresponse becomes available through a buffer in the form of a long
character string. Thus, direct data exchange does not take place.

Free download pdf