using classdef, is it possible to mix run-time data access through the dot syntax with methods elegantly?
2 次查看(过去 30 天)
显示 更早的评论
hi
i am developing a class (using classdef) that maintains a structure internally with fields that are instance-dependent. i want to provide direct access to these instance-dependent fields through object.fieldname syntax, so i use subsref and override fieldnames() so that tab completion works correctly.
trouble is, now all methods called using the syntax object.method() also result in calls to subsref, so i have to provide a case in subsref for every method of the class. this seems inelegant at best, and error prone at worst.
is there another way to achieve what i want?
thanks ben
0 个评论
采纳的回答
David Young
2011-12-4
"Elegantly" is hard to do in this context, I think. There's some discussion of this kind of issue here.
2 个评论
David Young
2011-12-5
Yes - my own view is that the design of subsref() isn't as helpful as it could be.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Construct and Work with Object Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!