Borrar filtros
Borrar filtros

Persistent variable clear after simulation with simulink

35 visualizaciones (últimos 30 días)
octus_ma
octus_ma el 25 de Mayo de 2016
Respondida: octus_ma el 26 de Mayo de 2016
Hello, i have a problem, where I need help. I have decleared and initilized a persistent variable var in a Matlab Embedded Function in Simulink. For example
persistent var
if isempty(var)
var= 1
end
I noticed that the variable doesn't exist after the simulation end's. Thats why var is initialized again, when i start a simulation. Is this normal ? (I don't have any function in Model Property)

Respuesta aceptada

Sebastian Castro
Sebastian Castro el 25 de Mayo de 2016
Yes. This is normal.
The persistent variable will persist between time steps of the simulation, i.e., between calls to the MATLAB Function. At the end of simulation, the variable will go out of scope.
What exactly are you trying to do between simulations with such a variable? Maybe there's another way.
- Sebastian
  2 comentarios
Walter Roberson
Walter Roberson el 26 de Mayo de 2016
I would gather from this that a "clear" is being one at some point ?
Though if it is one of the Accelerator modes then you are probably running a complete executable...
octus_ma
octus_ma el 26 de Mayo de 2016
No i tested it with a model only with this code in a Matlab Embedded Function

Iniciar sesión para comentar.

Más respuestas (1)

octus_ma
octus_ma el 26 de Mayo de 2016
Thank you

Categorías

Más información sobre Programmatic Model Editing 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