Search code examples
matlabapicomexportmatlab-figure

Exporting the output of MATLAB's methodsview


MATLAB's methodsview tool is handy when exploring the API provided by external classes (Java, COM, etc.). Below is an example of how this function works:

myApp = actxserver('Excel.Application');
methodsview(myApp)

Example output of methodsview for

I want to keep the information in this window for future reference, by exporting it to a table, a cell array of strings, a .csv or another similar format, preferably without using external tools.

Some things I tried:

  • This window allows selecting one line at a time and doing "Ctrl+c Ctrl+v" on it, which results in a tab-separated text that looks like this:

     Variant GetCustomListContents   (handle, int32)
    

    Such a strategy can work when there are only several methods, but not viable for (the usually-encountered) long lists.

  • I could not find a way to access the table data via the figure handle (w/o using external tools like findjobj or uiinspect), as findall(0,'Type','Figure') "do not see" the methodsview window/figure at all.

My MATLAB version is R2015a.


Solution

  • Fortunately, methodsview.m file is accessible and allows to get some insight on how the function works. Inside is the following comment:

    %// Internal use only: option is optional and if present and equal to
    %// 'noUI' this function returns methods information without displaying 
    %// the table. `
    

    After some trial and error, I saw that the following works:

    [titles,data] = methodsview(myApp,'noui');
    

    ... and returns two arrays of type java.lang.String[][].

    From there I found a couple of ways to present the data in a meaningful way:

    • Table:

      dataTable = cell2table(cell(data));
      dataTable.Properties.VariableNames = matlab.lang.makeValidName(cell(titles));
      

      Output as a table...

    • Cell array:

      dataCell = [cell(titles).'; cell(data)];
      

    Important note: In the table case, the "Return Type" column title gets renamed to ReturnType, since table titles have to be valid MATLAB identifiers, as mentioned in the docs.