Matlab - 我如何知道变量名是否可以自由使用

s5s*_*s5s 3 matlab

在MatLab中你说:

E = cell(3,1);
Run Code Online (Sandbox Code Playgroud)

我怎么知道E是否已经被使用并且上面的呼叫没有覆盖它?我是否必须运行该程序并在此时中断?解释器中有一种方法可以帮我吗?例如,在C++中,编译器会告诉您是否尝试使用现有名称.

tal*_*kol 8

根据此页面,您应该使用命令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)

  • 正确的形式是`存在('E','var')`来检查变量`E`是否存在,顺便说一下比`exists('E')== 1更容易理解 (3认同)