Borrar filtros
Borrar filtros

How can I skip initialization for a variable in further executions?

2 visualizaciones (últimos 30 días)
Jilan Samiuddin
Jilan Samiuddin el 24 de Mzo. de 2015
Editada: Walter Roberson el 6 de Mayo de 2015
I want to skip initialization of my variable in further executions of my function, except for the first time. e.g.
w_hat = w_nom; %initialization
w_hat = w_hat + del_w; %update of my variable
So for the first time I want w_hat to hold the value of w_nom, but in the next step when the function is recalled, I want w_hat to hold the value from its previous update. So how do I skip the initialization in the second and further steps?
Thanks in advance! I hope I was clear with my question.
**Updated: I will implement the function file in SIMULINK and so except for the first time the function is called, the objective is to initiate w_hat with the previous updated w_hat.
  1 comentario
Raghav
Raghav el 8 de Abr. de 2015
You can make use of persistent variables in this situation. Ex:
persistant w_hat;
if(isempty(w_hat))
w_hat = w_nom; %initialization
else
w_hat = w_hat + del_w; %update of my variable
end
Have a look at 'inmem' command as well. Hope this is what you were looking for.

Iniciar sesión para comentar.

Respuestas (1)

Star Strider
Star Strider el 24 de Mzo. de 2015
You are not re-initialising it, you are reassigning it with a new value with the update.
I believe that is what you want to do.
  8 comentarios
Jilan Samiuddin
Jilan Samiuddin el 25 de Mzo. de 2015
Thanks man. :)
I just hope I get some answer soon because it is pretty much urgent for me.

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by