Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a Matlab structure constant once it is already created?

Tags:

matlab

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?

like image 953
physmom Avatar asked Jul 23 '16 23:07

physmom


1 Answers

You should

  1. define the variable in the function to be persistent
  2. lock your function in the memory using 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.

like image 182
NKN Avatar answered Sep 25 '22 19:09

NKN