persistent variables are reinitialized ?

7 次查看(过去 30 天)
Dear all, I have a system which contains many subsystems each of them has a Matlab function block with its own persistent variables I display the variables during the run which usually takes hours, what I found that after a certain point all the persistent variables are reinitialized to its starting values! I do not know why?
I was looking for a solution I found that I should use mlock but it does not work in the matlab function block!, I added
coder.extrinsic('mlock');
mlock();
but I am getting this error
Call to MATLAB function aborted: "MLOCK" must be called from a file.
Component: Stateflow | Category: N.A.
Could you please help me solving this issue. Thank you,

回答(1 个)

Walter Roberson
Walter Roberson 2015-9-15
Generally speaking, persistent variables are reinitialized if the function they are in is ever cleared, either by way of an explicit
clear TheFunctionName
or by a
clear all
There may be some situations in Simulink or SimScape that I am not familiar with in which a clear is done. (For example it would not startle me if disabling a block or subsystem had that result.)
Please check your blocks for "clear" statements. If you find any "clear all" then you should definitely remove those statements.

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by