Maintaining function evaluation count in a class method

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!

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

질문:

2013년 2월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by