关于MatlabGUI清除WorkSpace的用法

近日在调试Matlba GUI程序时,因为不想退出程序后手动Clear All来清理,又需要在过程中对WorkSpace进行清理,否则会引用之前的结果导致错误,找了很多资料,国内的论坛什么的都说用Clear,Clear All这种,根本不行,会报错,因为过程中Clear将会导致定义的handles丢失,最后在Matlab的官方论坛中找到了答案:

Clear Global Workspace from GUI Pushbutton

"global (main)workspace" I assume/guess you refer to the baseworkspace.

Try something like

evalin('base','clearvars *' )

or

evalin('base', 'clear variables' )

in the callback function of the pushbutton. See the documentation on clearvars and on clear

说明是,必须加载在一个按钮的Callback中。

感谢参考:https://www.mathworks.com/matlabcentral/answers/79174-clear-global-workspace-from-gui-pushbutton 

原文地址:https://www.cnblogs.com/qiuya/p/10790463.html