MATLAB Answers


Can't shut down COM automation server instances of MATLAB

Asked by David
on 19 Nov 2012


I'm starting some automation server instances of ML:

for ix = 1:4
    servH(ix) = actxserver('Matlab.Application.Single');
    servH(ix).Visible = 0;
    % More code...

I do some stuff in each session, controlling each session with some PutWorkspaceData(), GetWorkspaceData(), and Execute() methods, and when I'm done, I tried to kill these instances in a couple of different ways, e.g.:



for ix = 1:4

The above seem to work when I attempt them from the command window (launching and killing from command window), but I can't seem to kill them from within my real program. The only thing that I could reliably use was (yes, it's ugly):

catch me
    % Killed server, and we get Error: RPC-server is unavailable

Am I missing something obvious here?

64-bit R2011b on Win7 by the way...



1 Answer

Answer by Kaustubha Govind
on 19 Nov 2012

Does servH(ix).Quit pass for ix=1 and fail thereafter? If yes, I wonder if you're calling the Quit method in a loop too quickly. You could try putting in a PAUSE command and see if that helps.


on 20 Nov 2012

Hi Kaustubha,

Thanks for the reply.

The answer would be yes. But the actual behaviour I see is just silent acceptance in MATLAB, with no errors or warnings. I did actually try putting pause, but sadly, it didn't change anything. In fact, I tried halting the execution inside the loop and step through it, and it still wouldn't quit.

I just did some additional tests, and when I test with a barebones sample (basically just start up the servers, and immediately invoke Quit), it seems to work. What I haven't fully understood yet is why my real code would be any different, as all I do is run a few Execute commands, and PutWorkspaceData and GetWorkspaceData... Even after completion of the function, I can access the servers from the command window with h = actxGetRunningServer('matlab.application'). h.Quit from here does not work either.

David: I don't have enough expertise in this area to make further suggestions. Could you please contact MathWorks Tech Support to see if they might be able to guide you better? Thanks!

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!