how to get and plot current "x" and "fval" during an fmincon optimization embedded in a GUI

4 views (last 30 days)
Hi,
I am writing an optimization code embedded in a GUI. Optimization works well at the moment, but I would like to improve the functionality of my GUI. In that context, I would like to plot a dynamic graph of "current point" and "current function value" of fmincon iterations on my GUI. My problems are:
1) I couldn't achieve to write an working Output function.
2) About GUI plot; I am not sure if I have to write plot command in my optimization function or in GUI callback
Thanks in advance
Sercan

Accepted Answer

Matt J
Matt J on 1 Nov 2012
  1. I don't know what the problem was with the OutputFcn, but this link gives an example almost identical to what you're talking about. In the OutputFcn in this example, the "history" structure dynamically accumulates the x and fval data and plots the x's.
  2. Since you say you want a "dynamic graph" I assume you want it to occur while the optimization is in progress. Therefore, the OutputFcn, and not the callback (and also not in your objective function), is the place to do that. The callback will only reacquire control of the program once the optimization has finished.
  4 Comments
Sercan
Sercan on 1 Nov 2012
Thanks for great help again, you really save me some precious time Matt. Explicit input way works proper. For the record, I have declared "global handles" inside the optmain because matlab didn't allow me to put it into innermost nested function, and that did not help me. But, now everything is ok.
Matt J
Matt J on 1 Nov 2012
OK, I don't know why the global variable approach wouldn't have worked, but it's always better not to use them.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!