在MatLab中你说:
E = cell(3,1);
Run Code Online (Sandbox Code Playgroud)
我怎么知道E是否已经被使用并且上面的呼叫没有覆盖它?我是否必须运行该程序并在此时中断?解释器中有一种方法可以帮我吗?例如,在C++中,编译器会告诉您是否尝试使用现有名称.
根据此页面,您应该使用命令exist:
help exist
EXIST Check if variables or functions are defined.
EXIST('A') returns:
0 if A does not exist
1 if A is a variable in the workspace
2 if A is an M-file on MATLAB's search path. It also returns 2 when
A is the full pathname to a file or when A is the name of an
ordinary file on MATLAB's search path
3 if A is a MEX- or DLL-file on MATLAB's search path
4 if A is a MDL-file on MATLAB's search path
5 if A is a built-in MATLAB function
6 if A is a P-file on MATLAB's search path
7 if A is a directory
8 if A is a Java class
Run Code Online (Sandbox Code Playgroud)