Indexed array access in a class method without subsref
3 views (last 30 days)
Show older comments
I'm converting a class in Matlab 2008 from a group of m files in an @className folder, and have run into issues trying to take the individual methods within the subsref file and make them into their own methods for the class. Specifically I can get them to work, so long as there are no indexed array calls to these methods from subsref. I cannot get around no longer supporting the indexed array access to subsref methods, as it would require too much time to enact in other portions of the code base. Is there any way to make indexed array access work and be able to pull the methods out of subsref?
2 Comments
Matt J
on 21 Mar 2014
Edited: Matt J
on 21 Mar 2014
Very little of this is clear (to me at least). What do you mean by "individual methods within the subsref file"? The subsref file would have contained only 1 method, namely the subsref method. Also what do you mean by an "indexed array call to a method"?
Accepted Answer
Matt J
on 21 Mar 2014
Edited: Matt J
on 21 Mar 2014
Implementing expressions of the form
T.geo( end, : )
is not possible when "geo" is a class method. Note that that is only true, however, because of the presence of colon expansions ':' and 'end' statements. If your indices will always be purely numeric, like in the following
T.geo(1:10,5:7)
then doing this through a class method called geo() is perfectly feasible.
Since you seem to want to use colons and "end"'s, one thing you might do is make "geo" a Dependent property (or maybe even a non-dependent one) that returns the matrix to be indexed. If you use a Dependent property, however, the class method set.geo() will have to construct the full matrix to be indexed, regardless of whether you only intend to extract a piece of it. If this is the very thing you were trying to avoid, you must use an overloaded SUBSREF, as in the original implementation.
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!