Starting Matlab as COM server and COM related issues
Mostrar comentarios más antiguos
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:
- It starts a new instance every time
- The started instance exits when the C# program exits
- 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:
- How do you start a desktop version of Matlab with COM server enabled, say from a shortcut?
- If #1 can't be done, how do you prevent Matlab from exiting if the calling program terminates?
- 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.
Respuestas (0)
Categorías
Más información sobre Write COM Applications to Work with MATLAB en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!