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!

답변 (1개)

Daniel Shub
Daniel Shub 2011년 6월 18일
I think you can overload subsref to get behavior like this.

댓글 수: 1

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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기

질문:

2011년 6월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by