是否可以有一个工作区变量在清除请求期间持续存在? [英] Is it possible to have a workspace variable that persists across a call to clear?
问题描述
假设我运行一个脚本X.m
,它创建了一堆变量,并且我想保存一个名为Z
的变量,所以我写myVar = Z
.
Suppose I run a script X.m
and it creates a bunch of variables, and I want to save a variable called Z
, so I write myVar = Z
.
然后我在提示符下键入clear
,然后运行Y.m
.
I then type clear
at the prompt, and run Y.m
.
有没有办法让我在调用clear
时myVar
不会与所有其他变量一起消失?
Is there a way I can make it so that myVar
does not disappear with all the other variables when I call clear
?
推荐答案
您可以使用 clearvars
清除工作区中除特定变量以外的所有变量.从clearvars
文档:
clearvars -except v1 v2 ...清除除那些变量以外的所有变量 在-except标志之后指定.使用通配符'' 在变量名中排除与模式匹配的变量 被清除. clearvars -except X 清除 当前工作空间,例如,以X开头的工作空间除外. 使用clearvars -except保留所需的变量并删除所有变量 其他人.
clearvars -except v1 v2 ... clears all variables except for those specified following the -except flag. Use the wildcard character '' in a variable name to exclude variables that match a pattern from being cleared. clearvars -except X clears all the variables in the current workspace, except for those that start with X, for instance. Use clearvars -except to keep the variables you want and remove all others.
因此,您需要输入
clearvars -except myVars
而不是clear
.
这篇关于是否可以有一个工作区变量在清除请求期间持续存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!