Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically return a list of all functions

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?

enter image description here

like image 224
zcaudate Avatar asked Aug 21 '18 05:08

zcaudate


1 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")).';
like image 96
Dev-iL Avatar answered Nov 15 '22 15:11

Dev-iL