I want to programmatically get a list of available functions in the current MATLAB namespace, as well the available functions in a package. How can this be done?
-
1I could be wrong but I believe every function in MATLAB needs an associated .m, .mex, or .mex64 file in the path. You could go through each entry in `path()` and find all such files. – jodag Aug 21 '18 at 07:26
-
@jodag: that works. I'll accept if you put your comment as an answer. – zcaudate Aug 21 '18 at 09:31
-
[This question](https://stackoverflow.com/q/37829489/3372061) might have some relevance to your problem. – Dev-iL Aug 21 '18 at 09:46
-
3Possible duplicate of [List of all built-in symbols in Matlab/Octave](https://stackoverflow.com/questions/49840280/list-of-all-built-in-symbols-in-matlab-octave) – Cris Luengo Aug 21 '18 at 13:12
-
1[My answer to that question ^](https://stackoverflow.com/a/49843752/7328782) contains code that lists all known functions and methods, and shows how to do the same for a `+namespace` package. – Cris Luengo Aug 21 '18 at 13:14
2 Answers
We can use package metadata for this:
pkgs = meta.package.getAllPackages();
% Or if the specific package name is known:
mp = meta.package.fromName('matlab')
The cell array returned in the 1st case, pkgs
, contains objects such as this:
package with properties:
Name: 'Sldv'
Description: ''
DetailedDescription: ''
ClassList: [29×1 meta.class]
FunctionList: [8×1 meta.method]
PackageList: [9×1 meta.package]
ContainingPackage: [0×0 meta.package]
So all that's left to do is iterate through the packages and sub-packages tand collect their FunctionList
entries.
I'm not sure how to get the functions that belong to the "default" namespace, other than by parsing the function list doc page, for example using the Python API and BeautifulSoup
:
fl = arrayfun(@(x)string(x{1}.string.char), py.bs4.BeautifulSoup( ...
fileread(fullfile(docroot,'matlab','functionlist-alpha.html')), ...
'html.parser').find_all("code")).';

- 23,742
- 7
- 57
- 99
-
1Parsing that page is [pretty easy](https://stackoverflow.com/a/51947138/3978545) :) – Wolfie Aug 21 '18 at 10:57
Further to Dev-iL's answer, parsing the function list documentation web page is pretty easy because of the useful "function" class that the web devs have (currently) used to tag each function name with! Each function looks like this within the HTML:
<code class="function">accumarray</code>
So we can use urlread
to grab the source, and regular expressions to strip out the inner text of each "function"
class item:
str = urlread('https://mathworks.com/help/matlab/functionlist-alpha.html');
funcs = regexp( str, '(?<="function">)[0-9A-Za-z.]+', 'match' );
Note: "alpha" in the URL is for "alphabetical" rather than to denote early testing!
funcs
is a cell array with all the function names on that page.
The page used above is for the most recent MATLAB version. For a specific version, use the historic documentation pages structured like so:
https://mathworks.com/help/releases/R2017b/matlab/functionlist.html

- 27,562
- 7
- 28
- 55
-
Neat answer, I would suggest however to use webread instead of urlread (it's deprecated), and you can remove the escape for the `.` in the character set. – Paolo Aug 21 '18 at 11:58
-
@UnbearableLightness `webread` kept timing out (at 20secs) in my quick tests, whereas `urlread` was basically instantaneous. – Wolfie Aug 21 '18 at 13:01