MATLAB: How to pass more parameters than the existing ones to output function of fmincon

fminconMATLABnonlinoptimizationOptimization Toolbox

The above link is to the documentation of Output Functions, a function that is evaluated at each individual iteration of fmincon. The parameters passed to it by default are x, optimValues and state.
1. How to pass extra parameters to this function?
2. Is there any way to compute a partial stepsize? Say numel(x) = 60 and I want to calculate stepsize norm(x(1:10)-xk(1:10)), is it possible? Because optimValues.stepsize calculates norm(x-xk) which is taking into account the entire vector.

Best Answer

To pass external parameters, use the documented ways. You can also use persistent variables within an output function.
Alan Weiss
MATLAB mathematical toolbox documentation