一个人怎么能清除所有想要的变量 [英] How can one clear all the variables but the ones wanted

查看:103
本文介绍了一个人怎么能清除所有想要的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,当运行长内存的昂贵程序时,我想清除除某些特定变量之外的所有内容.如果只想删除一些变量,可以使用clear varA varB,但是删除除此特定变量之外的所有变量该怎么办?

Often when running long memory expensive programs I want to clear everything but some specific variables. If one wants to delete just some variables clear varA varB can be used, but what about deleting all but this specific variables?

推荐答案

如上所述, clearvars 包括一种语法,用于在清除剩余部分的同时将变量保留在工作空间中:

As mentioned above, clearvars includes a syntax for keeping variables in the workspace while clearing the remainder:

a = 1; b = 1; c = 1; d = 1;
keepvars = {'c', 'd'};

clearvars('-except', keepvars{:});

可以正常运行.

类似于 clear ,它也可以容纳

Like clear, it can also accommodate regexp matching:

a1 = 1; a2 = 1; b = 1; c = 1;
keepvars = 'a\d'; % regex pattern

clearvars('-except', '-regexp', keepvars);

按预期保留了a1a2.

这篇关于一个人怎么能清除所有想要的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆