Documentation Center

  • Trial Software
  • Product Updates

Attach to Existing MATLAB Sessions

This example shows how to attach an engine program to a MATLAB® session that is already running.

On a Windows® platform, start MATLAB with /Automation in the command line. When you call engOpen, it connects to this existing session. You should only call engOpen once, because any engOpen calls now connect to this one MATLAB session.

The /Automation option also causes the command window to be minimized. You must open it manually.

On the Mac and Linux® platforms, you cannot make an engine program connect to an existing MATLAB session.

Shut down any MATLAB sessions.

From the Start button on the Windows menu bar, click Run.

In the Open field, type the value returned by the command:


Click OK. This starts MATLAB.

In MATLAB, compile the engwindemo.c example.

mex -client engine engwindemo.c 

Run the engwindemo program by typing at the MATLAB prompt:


This does not start another MATLAB session, but rather uses the MATLAB session that is already open.

More About

Was this topic helpful?