问题
How does one list/view/clear persistent variables in MATLAB? I'd like to see persistent variables not for a particular function, but for all functions that have persistent variables currently in memory.
I've tried things like whos('persistent')
and whos('global')
with no luck.
回答1:
If you want to clear a persistent from outside of the function within which it's defined, then you need to clear the function itself:
clear functionNameWithPersistentVariable
Or clear all (unlocked) functions from memory:
clear functions
If the function in question is actually a method of a class, you may need to use clear classes
instead. See also this table in the documentation for clear
.
Within the function itself you may be able to use whos
and something like the suggestion in this Matlab Central answer. Unfortunately, I don't know of any elegant documented way to find or list functions or persistent variables that are currently in memory.
来源:https://stackoverflow.com/questions/19800424/list-view-clear-persistent-variables-in-matlab