Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of all built-in symbols in Matlab/Octave

Tags:

matlab

octave

In Mathematica one can get the names of all built-in functions starting with, for instance, List by executing the command

Names["List`*"]

In addition

Names["context`*"] 

lists all symbols in the specified context. E.g.

Names["Global`*"] 

gives the names of all the built-in symbols (as well those defined by the user in Global context if any).

Are there similar structures in Matlab/Octave?

like image 221
Dimitris Avatar asked Jan 03 '23 13:01

Dimitris


2 Answers

In Octave you can use the following functions:

__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.

And undocumented function __dump_symtab_info__ that dumps symbol table that contains function and variable names in different scopes:

__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
like image 83
rahnema1 Avatar answered Jan 13 '23 14:01

rahnema1


As far as I know, there is no equivalent to Octave's __list_functions__ in MATLAB. But it is quite easy to build one:

% 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);

The above skips functions defined within a package (these are functions called as package.function, package files start with a + character). Doing what('package') will give more function and class names to add to the lists.

Note that this does not limit to built-in functions, as in the question. It lists all functions on the search path. To limit to built-in functions, search only the directories within toolbox/matlab.

I don't know of any way to list operators and keywords, but that is a short list that can easily be hard-coded. MATLAB has a function iskeyword that will tell you if a given name is that of keyword or not. The source to this function (type iskeyword or edit iskeyword) contains this list.

Here are all operators.


Related, the function inmem lists all functions currently loaded. These are the functions you have actually used since MATLAB started, or since you last called clear functions or clear all. Note that functions can lock themselves in memory and not be cleared with clear functions.

like image 31
Cris Luengo Avatar answered Jan 13 '23 12:01

Cris Luengo