access a variable from the last iteration of optimization function: fmincon
Show older comments
I am using "fmincon" to optimize an objective function. MATLAB does iteration until one of the exit criteria happens. What I need is to use the value of a variables in my "objective function" code from the last step in current step. Actually, I wanna know if one variable in current step is equal to its value of the previous steps. I am grateful for any help.
Answers (1)
Walter Roberson
on 3 Apr 2011
0 votes
You could use "global" or "persistent" but note that fmincon doesn't promise to evaluate in any particular order.
2 Comments
Ibehma01
on 3 Apr 2011
Walter Roberson
on 3 Apr 2011
You need to assign the new value to the global variable before leaving the evaluation function.
You can detect that you are on the first iteration of the function because the global variable will have the empty array for its value. Unless, of course, you ran the function before in the same session without clearing the global variable...
Categories
Find more on Choose a Solver in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!