您可以使用gnovice注释中引用的其他答案的技术来获取A(B)对中的函数依赖关系列表,其中A调用B.然后安装
GraphViz并使用它来生成图表.您可以从Matlab创建.dot文件.
function createFunctionDependencyDotFile(calls)
%CREATEFUNCTIONDEPENDENCYDOTFILE Create a GraphViz DOT diagram file from function call list
%
% Calls (cellstr) is an n-by-2 cell array in format {caller,callee;...}.
%
% Example:
% calls = { 'foo','X'; 'bar','Y'; 'foo','Z'; 'foo','bar'; 'bar','bar'};
% createFunctionDependencyDotFile(calls)
baseName = 'functionCalls';
dotFile = [baseName '.dot'];
fid = fopen(dotFile, 'w');
fprintf(fid, 'digraph G {\n');
for i = 1:size(calls,1)
[parent,child] = calls{i,:};
fprintf(fid, ' "%s" -> "%s"\n', parent, child);
end
fprintf(fid, '}\n');
fclose(fid);
% Render to image
imageFile = [baseName '.png'];
% Assumes the GraphViz bin dir is on the path; if not, use full path to dot.exe
cmd = sprintf('dot -Tpng -Gsize="2,2" "%s" -o"%s"', dotFile, imageFile);
system(cmd);
fprintf('Wrote to %s\n', imageFile);
GraphViz适用于许多其他树和图形应用程序,如类继承和依赖关系树,数据流等.