Starting Matlab as COM server and COM related issues

2 views (last 30 days)
I am attempting to communicate with Matlab through a C# application. My goal is to be able to run commands sent from C# in the Matlab command window, and I have chosen COM to accomplish this. I am currently calling Matlab like so:
Type matlabType = Type.GetTypeFromProgID("Matlab.Desktop.Application");
MLApp.MLApp matlab = (MLApp.MLApp) Activator.CreateInstance(matlabType);
This will launch a new instance of Matlab (notice that I explicitly called the JVM version), and I can interface with it using the .Execute() member function. However, there are several problems with this:
  1. It starts a new instance every time
  2. The started instance exits when the C# program exits
  3. With the exception of input(), any text displayed in the command window is automatically forwarded to the C# application. As a result fprintf() and the like don't show anything in the command window.
I noticed that I am able to use Marshal.GetActiveObject() to connect to a running instance of Matlab, but ONLY if said instance was started via the method above; it won't work if Matlab was started normally, say from a shortcut. I suspect that this is because by default Matlab doesn't start with the COM server enabled.
Thus, my questions are:
  1. How do you start a desktop version of Matlab with COM server enabled, say from a shortcut?
  2. If #1 can't be done, how do you prevent Matlab from exiting if the calling program terminates?
  3. How do you disable redirection of output, such that the command window will behave as if the executed statement was inputted through the command window?
Note that I specify the desktop version everywhere possible; I don't want the -nojvm (pure command window) instances because I need the JVM.

Answers (0)

Categories

Find more on Write COM Applications to Work with MATLAB in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!