在MATLAB中分析单元格而不是函数

时间:2013-05-12 13:59:48

标签: matlab profiler

我有一个函数,反过来调用更多的函数。我想使用分析器来确定代码的哪些部分最需要时间。

是否可以获取配置文件摘要按单元格排序,而不是函数调用?

例如,是否可以让分析器输出:

  Cells    Calls   Total time ...  
  Part 1       1         .... ...
  Part 2       1         .... ...

而不是:

  Function name   Calls   Total time ...  
  func1               1         .... ...
  func2               1         .... ...

以下代码:

%% Part 1:
a = 1;
b = 2;
X = func1(a,b);

%% Part 2:
c = a+b;
Y = func2(c,b);

谢谢!

1 个答案:

答案 0 :(得分:2)

嗯,您可以随时提取每个单元格的分析信息,如下所示:

%% Part 1
profile on
%// Some code...
profile off
S1 = profile('info');

%% Part 2
profile on
%// Some more code...
profile off
S2 = profile('info');

结构S1S2应保存每个单元格的分析信息。请记住在每个代码单元的开头和结尾放置profile onprofile off以重置分析信息。

要以HTML格式查看个人资料信息,您可以使用profview。例如:

profview(0, S1)

第一个参数是配置文件信息结构的FunctionTable字段中的索引,它对应于要在配置文件查看器中显示的功能。