persistent variables are reinitialized ?
7 views (last 30 days)
Show older comments
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,
0 Comments
Answers (1)
Walter Roberson
on 15 Sep 2015
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.
0 Comments
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!