Documentation

清除

Remove items from workspace, freeing up system memory

Syntax

清除
清除name1 ... nameN
clear -regexpexpr1 ... exprn
清除ItemType

Description

清除从当前工作区中删除所有变量,从系统内存中释放它们。

example

清除name1 ... nameNremoves the variables, scripts, functions, or MEX-functionsname1 ... nameNfrom memory.

Ifnameis

  • 一个函数,然后清除重新引导功能中的任何持续变量

  • 当前正在执行的脚本或函数,然后清除不删除它

  • 锁定的功能mlock, then清除不删除它

  • 一个variable that is global, then清除removes it from the current workspace, but it remains in the global workspace

example

clear -regexpexpr1 ... exprn删除与列出的任何正则表达式匹配的所有变量。此选项仅删除变量。

example

清除ItemTyperemoves the types of items indicated byItemType, such as全部,功能, orclasses.

Examples

collapse all

Define two variablesab, 和then cleara.

a = 1; b = 2; cleara

Only variablebremains in the workspace.

whos
Name Size Bytes Class Attributes b 1x1 8 double

使用正则表达式,清除这些变量,其名称开头Mon,星期二, orWed.

清除-  regexp^MON^Tue^Wed;

Create a cell array,vars,其中包含要清除的变量的名称。然后,清除这些变量。

vars = {'v1','v2','time'}; clear(vars{:})

If a function is locked or currently running, it is not cleared from memory.

清除功能

Input Arguments

collapse all

Names of variables, scripts, functions, or MEX-functions to clear, specified as one or more character vectors.

采用a partial path to distinguish between different overloaded versions of a function. For example,清除多位数/display清除s only the展示方法多位数objects, leaving any other implementations in memory.

匹配变量名称以清除的正则表达式,指定为一个或多个字符向量。

Type of items to clear, specified as one of the following.

Value ofItemType 清理物品 不tes
Variables in scope 脚本和函数 类定义 持续变量 MEX functions Global variables 导入列表 Java classes on the dynamic path

全部

From command prompt only

打电话清除全部降低代码性能,通常是不必要的。For more information, see the尖端部分。

classes

打电话清除classes降低代码性能,通常是不必要的。For more information, see the尖端部分。

To instantiate an object with an updated class definition, it is not necessary to call清除classes. When you modify a class definition, MATLAB®updates it automatically. For more information, see一个utomatic Updates for Modified Classes.

清除classes发出警告,如果清除工作空间后仍然存在这些对象,则不会清除一类对象。例如,对象仍然可以存在于函数或图形窗口的持久变量中。

清除classesdoes not clear a class if its file is locked using themlock命令。在这种情况下,没有发出警告。

功能

打电话清除功能降低代码性能,通常是不必要的。For more information, see the尖端部分。

global

清除globalremoves all global variables in the current and global workspaces. For example, when called from a function,清除globalremoves all global variables in the function and global workspaces, but not in the base workspace.

import

Call清晰的进口仅来自命令提示。打电话清晰的进口in a function or a script returns an error.

java

清除java发出警告,如果其Java对象都存在于工作区外(例如,在用户数据或锁定代码文件中的持久变量中),则不会删除Java类定义。

Issue a清除javacommand after modifying any files on the dynamic Java path.

梅克斯

清除梅克斯does not clear locked MEX functions or functions that are currently in use.

variables

    不te:如果变量的名称是一个值ItemType, then calling清除其次是该名称以该名称删除变量。清除does not interpret the name as a keyword in this context. For example, if the workspace contains variablesa,全部,b, 和,清除全部removes the variable全部only.

尖端

  • 打电话清除全部,清除classes, 和清除功能降低代码性能,通常是不必要的。

    • To clear one or more specific variables from the current workspace, use清除name1 ... nameN.

    • 要清除当前工作空间中的所有变量,请使用清除或者清晰.

    • 要清除所有全局变量,请使用清除global或者清晰–global.

    • To clear a particular class, use清除myClass.

    • To clear a particular function or script, use清除函数名称.

    • To clear all MEX functions, use清除梅克斯.

  • The清除函数可以删除您指定的变量。要删除除几个指定变量以外的所有内容,请使用清晰instead.

  • 如果清除图形或图形对象的句柄,则不会删除对象本身。采用删除删除对象。另一方面,删除对象不会删除用于存储其手柄的变量(如果有的话)。

  • The清除function does not clear Simulink®楷模。采用bdcloseinstead.

  • 在Unix上®systems,清除does not affect the amount of memory allocated to the MATLAB process.

在R2006a之前引入

这个话题有帮助吗?