在MATLAB中clear(Filename)做了什么?

时间:2011-06-12 07:22:31

标签: matlab clear

files=dir('*.cpp');
for i=1:length(files)
    Filename=files(i).name;
    clear(Filename); 
    ......
end

有人可以解释清楚(文件名)的作用吗?我认为它不会删除变量Filename,因为我仍然在工作场所看到该变量。

2 个答案:

答案 0 :(得分:1)

它正在清除变量文件(i).name,其中files(i).name被评估为filname的名称

假设您有一个名为'test.cpp'的变量,以及一个名为'test.cpp'的文件名 这将清除工作区中的变量'test.cpp'

答案 1 :(得分:1)

clear(str)将清除名称由str中的字符串给出的变量。来自documentation

  

clear('name1','name2','name3',...)是语法的函数形式。将此表单用于存储在字符串中的变量名称和函数名称。

因此,在您的情况下,它正在清除名称为files(i).name中的字符串的变量。

实施例

>> a=1:10;
>> str='a';

%#check what variables are in the workspace
>> whos
  Name      Size            Bytes  Class     Attributes

  a         1x10               80  double              
  str       1x1                 2  char                

>> clear(str)

%#check again
>> whos
  Name      Size            Bytes  Class    Attributes

  str       1x1                 2  char        
相关问题