Matlab/Octave 中的所有内置符号列表

List of all built-in symbols in Matlab/Octave

在 Mathematica 中,可以通过执行命令

获取所有以 List 开头的内置函数的名称
Names["List`*"]

另外

Names["context`*"] 

列出指定上下文中的所有符号。例如。

Names["Global`*"] 

给出所有内置符号的名称(以及用户在全局上下文中定义的符号,如果有的话)。

Matlab/Octave有没有类似的结构?

在 Octave 中您可以使用以下功能:

__operators__              : Undocumented
__keywords__               : Undocumented
__builtins__               : Undocumented
__list_functions__         : Return a list of all functions (.m and .oct functions) in the load path or in the specified directory.
localfunctions             : Return a list of all local functions, i.e., subfunctions, within the current file.

和未记录的函数 __dump_symtab_info__ 转储包含不同范围内的函数和变量名称的符号 table:

__dump_symtab_info__ (scope)               : Dump symbol table of the given scope
__dump_symtab_info__ (__current_scope__)   : Dump symbol table of the current scope
__dump_symtab_info__ ("functions")         : Dump globally visible functions from symbol table
__dump_symtab_info__ ("scopes")            : List available scopes
__dump_symtab_info__ ()                    : Everything

据我所知,在 MATLAB 中没有与 Octave 的 __list_functions__ 等价的东西。但是构建一个非常容易:

% Generate a list of all directories searched by MATLAB:
pathlist = strsplit(path,pathsep);
% Get functions and classes on search path
functions = {};
classes = {};
for p = pathlist
   w = what(p{1});
   functions = [functions; ...
                erase(w.m,'.m'); ...           % M-files
                erase(w.mex,['.',mexext]); ... % MEX-files
                erase(w.p,'.p')];              % and P-files are all functions
   classes = [classes; w.classes];             % here are all classes 
   % TODO: w.packages gives package directory names, examine those too!
end
% Remove duplicates
functions = unique(functions);
classes = unique(classes);

以上跳过了包中定义的函数(这些函数称为 package.function,包文件以 + 字符开头)。执行 what('package') 将提供更多功能和 class 名称以添加到列表中。

请注意,这并不限于问题中的内置函数。它列出了搜索路径上的所有函数。要限制为内置函数,请仅搜索 toolbox/matlab.

内的目录

我不知道有什么方法可以列出运算符和关键字,但这是一个很短的列表,可以很容易地进行硬编码。 MATLAB 有一个函数 iskeyword 可以告诉您给定的名称是否是关键字的名称。此函数的源代码(type iskeywordedit iskeyword)包含此列表。

Here are all operators.


相关,函数inmem列出了当前加载的所有函数。这些是您自 MATLAB 启动以来或自您上次调用 clear functionsclear all 以来实际使用过的函数。请注意,函数可以将自己锁定在内存中,并且不会被 clear functions.

清除