Ok, so I figured I could use the Output Function to create a threshold and stop the optimization:
function stop = stopfunction(optimValues)
stop=false;
if optimValues.fval <= 7e-3
stop = true;
end
end
and then use this function in my main code by changing my options to:
options=optimoptions('patternsearch','Display','iter',...
'MeshTolerance',1e-10, 'ScaleMesh', false,...
'PlotFcn',@psplotbestf,...
'UseCompletePoll',true,'ConstraintTolerance',0.1,'OutputFcn',@stopfunction);
This seems to be the way to solve my problem.
However, when running the code, I get an error message:
"Error using stopfunction
Too many output arguments."
Any idea where the problem might be?