I am trying to run my mex function using the out of process matlab mexhost function. I am using the following wrapper to call my mex function.
function [t,y] = myfunction(x0,tspan)
if ~(isa(mh,'matlab.mex.MexHost') && isvalid(mh))
mh = mexhost;
[t,y] = feval(mh,"myfunctionMEX",x0,tspan);
I can use this wrapper 3 times before my function crashes and gives the error "Error executing C++ MEX function 'myfunctionMEX'. 'MATLABMexHost' with process ID '20172' crashed or was destroyed outside MATLAB." Can anyone help figure out why I can only run this a few times? I am trying to call it 4 times within the same script, but can only make it through 3 times without crashing. I am not calling clear or delete that would intentionally destroy the process.