access a variable from the last iteration of optimization function: fmincon

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.

답변 (1개)

Walter Roberson
Walter Roberson 2011년 4월 3일

0 개 추천

You could use "global" or "persistent" but note that fmincon doesn't promise to evaluate in any particular order.

댓글 수: 2

Thanks, I did... May be I did it wrong, I don't know, but it didn't work. When I define a variable as global, it won't change at all. What I need is to recall a variable in my objective function that was calculated one iteration before.
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...

댓글을 달려면 로그인하십시오.

태그

질문:

2011년 4월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by