default overloading method? or a way to return subclass objects of built-in classes?

I am trying to create a class that has some property, 'matrix'. If I have not explicitly defined an overloaded method for some function for my class, I would like to have it operate on this property, matrix, and then wrap it back up as an object of my class. Without a default method, I might have to use repeated try catch statements such as (for a simple with a single input and output):
try
output_argument = some_function(obj);
catch ME
if ME.identifier ... indicates the function only takes doubles
output_argument = make_obj(some_function(obj.matrix)),obj_template);
end
end
Is it possible to define a default catchall like this?
If that's not possible, is there a way to change the default behavior so that operations on subclasses of built-in classes return subclasses? (instead of "Operations on data values return objects of the superclass" as seen here http://www.mathworks.es/help/techdoc/matlab_oop/brgze9_-1.html#brr3cdl-1)
Thanks!

Antworten (1)

Daniel Shub
Daniel Shub am 18 Jun. 2011
I think you can overload subsref to get behavior like this.

1 Kommentar

Can you provide an example of how one might do so? I was under the impression that subsref/subsasgn will only act when the object is indexed/used as an index.
i.e. A(B) for A an object and/or B an object, not for A a function.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Construct and Work with Object Arrays finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 18 Jun. 2011

Community Treasure Hunt

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

Start Hunting!

Translated by