user466534
user466534

Reputation:

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 enter image description here

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?

Upvotes: 2

Views: 84

Answers (1)

NKN
NKN

Reputation: 6434

It actually works but when the function is terminated, the function workspace is deleted. You can check this by add a BreakPoint as follows:

enter image description here

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

Upvotes: 3

Related Questions