What is clear (file name) in MATLAB?

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

Can someone explain what makes clear (Filename)? I think that it does not delete the Filename variable, because I still see this variable in the workplace.

+4
source share
2 answers

clear(str) will clear the variable whose name is given by the string in str. From the doc:

clear('name1','name2','name3',...) is a form of syntax function. Use this form for variable names and function names stored in strings.

So, in your case, it clears a variable whose name is a string in files files(i).name .

Example:

 >> 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 
+1
source

It clears the variable files (i) .name, where the files (i) .name are evaluated with the name filname

Suppose you have a variable called "test.cpp" and a file name called "test.cpp" This will clear the test.cpp variable from your workspace.

+1
source

All Articles