Persistent variable clear after simulation with simulink

조회 수: 7 (최근 30일)
octus_ma
octus_ma 2016년 5월 25일
답변: octus_ma 2016년 5월 26일
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)

채택된 답변

Sebastian Castro
Sebastian Castro 2016년 5월 25일
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
Walter Roberson
Walter Roberson 2016년 5월 26일
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 2016년 5월 26일
No i tested it with a model only with this code in a Matlab Embedded Function

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

추가 답변 (1개)

octus_ma
octus_ma 2016년 5월 26일
Thank you

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by