MATLAB: Save output from ‘Display’ option when using fminsearch to object

optimization fminsearch iterative display

I am using fminsearch to find the minimum of an objective function, but I want to be able to store the progress at each iteration in terms of the function value/action taken at that iteration. The following code prints out the information I want to the matlab terminal,
options = optimset('Display','iter')
[x,fval,exitflag,output] = fminsearch(fun,x0,options)
though I don't know how to save it to an object that I can use later on for analysis. Is this possible?

Best Answer

You should use the OutputFcn option, specifically, to save the optimValues inputs automatically fed to the Output Function that you specify.