It is not always necessary to create a new instance of a MATLAB® server whenever your application needs some task done in MATLAB. Clients can connect to an existing MATLAB Automation server using the actxGetRunningServer function or by using a command similar to the Visual Basic® .NET GetObject command.
The Visual Basic .NET command shown here returns a handle h to the MATLAB server application:
h = GetObject(, "matlab.application")
Note: It is important to use the syntax shown above to connect to an existing MATLAB Automation server. Omit the first argument, and make sure the second argument is as shown.
The following Visual Basic .NET example connects to an existing MATLAB server, then executes a plot command in the server. If you do not already have a MATLAB server running, create one following the instructions in Accessing Methods from the Visual Basic Object Browser.
Dim h As Object h = GetObject(, "matlab.application") ' Handle h should be valid now. ' Test it by calling Execute. h.Execute ("plot([0 18], [7 23])")