There are a couple of ways to implement this based on your client application:
While using a Visual Basic .NET client application, modify your client program as follows:
Dim MatLab As Object
Dim Result As String
Dim out1 As Object
MatLab = CreateObject("Matlab.Application")
Matlab.Feval("enableservice", 1, out1, "AutomationServer", True)
'Executing other MATLAB commands
Result = MatLab.Execute("surf(peaks)")
In the above code, FEVAL is used to execute the MATLAB Command:
enableservice('AutomationServer',true)
which sets MATLAB's state to an Automation Server and does not terminate it when the client application terminates.
If the client application is a C/C++ program, the MATLAB Server is typically created using the MATLAB Engine API functions like engOpen( ). In this case, the following line can be added to the engine C/C++ code to prevent MATLAB from terminating even though the client application terminates:
engEvalString(ep,"enableservice('AutomationServer',true)");
The service can be closed using the following command either with FEVAL or ENGEVALSTRING depending on hoe the service was enabled:
enableservice('AutomationServer',false);
Best Answer