导出 MATLAB 方法视图的输出

Exporting the output of MATLAB's methodsview

MATLAB 的 methodsview 工具在探索外部 类(Java、COM 等)提供的 API 时非常方便。下面是此函数如何工作的示例:

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

我想保留此 window 中的信息以供将来参考,方法是将其导出到 table、cell 字符串数组、.csv 或另一种类似的格式,最好不使用外部工具。

我试过的一些东西:

我的 MATLAB 版本是 R2015a。

幸运的是,methodsview.m 文件是可访问的,可以让我们深入了解函数的工作原理。里面是下面的评论:

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

经过反复试验,我看到了以下效果:

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

... 和 returns 两个 java.lang.String[][].

类型的数组

从那里我找到了几种以有意义的方式呈现数据的方法:

  • Table:

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

  • 元胞数组:

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

重要说明:在 table 情况下,“Return Type”列标题重命名为 ReturnType,因为 table 标题必须是有效的 MATLAB 标识符, as mentioned in the docs.