Suppose I have a function defined in foo.m
. This function can take a parameter thing
of type struct
. Once foo
makes changes to thing
, I want to "lock" thing
so that it can no longer be changed. I essentially want to make it constant. I want to do this to ensure it isn't modified further down the line. How do I do this in Matlab?
You should
persistent
mlock
.mlock
locks the currently running function in memory so that subsequent clear
functions do not remove it. Locking a function in memory also prevents any persistent variables defined in the file from getting reinitialized.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With