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!