files=dir('*.cpp');
for i=1:length(files)
Filename=files(i).name;
clear(Filename);
......
end
任何人都可以解释清楚(文件名)的作用吗?我认为它不会删除变量Filename,因为我仍然在工作场所看到该变量.
最佳答案 clear(str)将清除名称由str中的字符串给出的变量.从
documentation:
clear('name1','name2','name3',...)
is the function form of the syntax. Use this form for variable names and function names stored in strings.
因此,在您的情况下,它正在清除名称为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