MATLAB: How to get values for each iteration on optimization toolbox

fminconMATLABoptimizationOptimization Toolbox

I am using MATLAB optimization toolbox. I want to know how can I get values on each iteration, such as objective function value, or variable values. I am using fmincon function. So long What I can get is only the final value of the variables and the final value of the objective function after some iterations. I want to get those values for each iteration, saving them anywhere, but preferably on a .txt file or displaying them on the screen.
Thanks and regards, Hugo Silva, Eng. MSc.

Best Answer

Use the OutputFcn option, such as in the example here