Programming and Data Types    

Persistent Variables

A variable may be defined as persistent so that it does not change value from one call to another. Persistent variables may be used within a function only. Persistent variables remain in memory until the M-file is cleared or changed.

persistent is exactly like global, except that the variable name is not in the global workspace, and the value is reset if the M-file is changed or cleared.

Three MATLAB functions support the use of persistent variables.

Function
Description
mlock
Prevents an M-file from being cleared
munlock
Unlocks an M-file that had previously been locked by mlock
mislocked
Indicates whether an M-file can be cleared or not


 Local and Global Variables Special Values