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에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!