简体   繁体   中英

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

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:

在此处输入图片说明

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')
% --------------------------

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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