How to use previous result in objective function?

I'm currently working on a filter coefficient optimization problem. I'm using global optimization toolbox and the objective function is a bit complicated Now I want to use previous calculation results in the objective function, but I don't want to set those values as variables because they are fixed. I tried to write the objective function in function handles but I failed because for loop is needed to get this objective function. Is there anyway that I can use the previous calculation results in a new function, but not claiming them as variables?

 Respuesta aceptada

John D'Errico
John D'Errico el 9 de Feb. de 2017

0 votos

Once your objective function exits from the previous call, anything you did there gets dumped in the bit bucket. Lost forever.
You have two choices.
1. Use save to save values out to an m-file. This will be time consuming, something you really don't want to do, because it involves disk access.
2. Learn how to use persistent variables.

1 comentario

Gelei Deng
Gelei Deng el 9 de Feb. de 2017
Thank you so much! I just checked the documentation of persistent variables and it should work.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 9 de Feb. de 2017

Comentada:

el 9 de Feb. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by