Maintaining function evaluation count in a class method

1 回表示 (過去 30 日間)
Sumeet
Sumeet 2013 年 2 月 11 日
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!

採用された回答

Honglei Chen
Honglei Chen 2013 年 2 月 11 日

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConstruct and Work with Object Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by