简体   繁体   English

在功能中使用matlab的配置文件属性

[英]use profile property of matlab in function

let us consider following code 让我们考虑以下代码

function  [y,m]=fibonacci(n);
% return nth fibonnaci number
profile on
y=zeros(1,n);
y(1)=0;
y(2)=1;
 for k=3:n
     y(k)=y(k-1)+y(k-2);
 end
 m=y(n);
 profile viewer
p = profile('info');
profsave(p,'profile_results')
end

of course i can use tic and toc function in matlab to calculate how much time will taken by this function, but i want for self learning , customize with profile tools in matlab, for instance let us consider following little code 当然,我可以在matlab中使用tic和toc函数来计算此功能将花费多少时间,但是我想进行自学,请在matlab中使用配置文件工具进行自定义,例如让我们考虑遵循以下代码

profile on
plot(magic(35))
profile viewer
p = profile('info');
profsave(p,'profile_results')

result is given 结果给出 在此处输入图片说明

i want to use same property in function, but is says that now built in function is used here, so can i use profile properties in function? 我想在函数中使用相同的属性,但据说现在使用内置函数,因此可以在函数中使用配置文件属性吗?

It actually works but when the function is terminated, the function workspace is deleted. 它实际上可以工作,但是当函数终止时,将删除函数工作区。 You can check this by add a BreakPoint as follows: 您可以通过添加BreakPoint进行检查,如下所示:

在此处输入图片说明

I think there is no way that you can see the information just using a single function as you requested. 我认为您无法仅使用所需的功能就可以查看信息。 But you always can have a main file and profile the function from there, and the profiler gives you all of the information: 但是,您始终可以拥有一个主文件,并从那里对函数进行概要分析,并且概要分析器为您提供了所有信息:

% --------- main.m --------
profile on
fibonacci(100);
profile viewer
p = profile('info');
profsave(p,'profile_results')
% --------------------------

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM