I have a Simulink model which loads a DLL and uses some mex files in simulink blocks. When I stop the Simulation, I would like the DLL unloaded. Using "clear mex" works for this purpose. I put "clear mex;" in the StopFcn callback of the model so that this is done every time the Simulation stops, but it does not seem to be working. If I execute "clear mex" from the command line after simulation ends, it does clear the mex files.
Is this incorrect use of the StopFcn callback? How can I make the mex file clear (and thus have the DLL unloaded) after the Simulation is stopped?
Best Answer