Maintaining function evaluation count in a class method

3 views (last 30 days)
Hi,
I've defined a functioneval method in a class. It returns the value of the function at an input point. However, I also with to maintain a count of how many times functioneval has been called. How do I accomplish this?
Here is what I tried: I created a property called functionevalcount and increased it by 1 in the functioneval method.
function feval = functioneval(obj)
feval = <computations>
obj.functionevalcount = obj.functionevalcount + 1;
end
However, I learnt that matlab class methods operate by value, and so the change in the functionevalcount isn't reflected outside. I need to return obj as well.
function [feval,obj] = functioneval(obj)
The functioneval method is called from many other methods of the same class, and they will all have to start returning obj as well. This will disrupt the entire structure of my program.
Is there a way I can compute the functionevalcount without having to return the object (something akin to pass by reference)?
Thanks!

Accepted Answer

Honglei Chen
Honglei Chen on 11 Feb 2013

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!