9.3 TheMatlabengine functions 291
whereepis a chosen pointer name. This declaration illustrates thatEngineis
a defined class.
Starting aMatlabsession
To start aMatlabsession identified by the pointerep, we state:
ep = engOpen("matlab");
The launching command matlabcan be replaced by any other string that
invokesMatlabwith options. For example, to suppress the graphical user
interface, we use:
ep = engOpen("matlab -nodesktop");
Equivalently, we can state:
char mstart[] = "matlab";
ep = engOpen(mstart);
In a third method, we explicitly use a pointer:
string invoke[] = "matlab";
char * pnt = invoke;
ep = engOpen(pnt);
Terminating aMatlabsession
To terminate theMatlabsession, we issue the statement:
engClose(ep);
The functionengClosereturns an integer.
Establishing a buffer
C++ has access to a character buffer that records the standard output
ofMatlab, that is, it records output that ordinarily appears on the screen.
To establish this buffer, we select its size, declare a dedicated character
string, and attach the character string to theMatlabsession by issuing the
commands:
const int Bufsize = 256;
char Bufname[];