|
"Sebastian Hölz" wrote in message <jembt8$1f3$1@newscl01ah.mathworks.com>...
> I have a handle class with an add-method to extend existing object:
>
> classdef Obj_A < hgsetget
> % some props and constructor, which handles nargin==0
> methods
> function obj = add(obj)
> % Some input parsing
> obj(end+1) = MyObj
================
A few preliminary questions. First, how does MyObj get into the workspace of the add method? You have passed only obj... Did you mean the following?
obj(end+1) = obj
Or did you mean to have the calling signature to be this:
function add(obj,MyObj)
If the latter, I don't see why you don't just use the default cat operations, e.g.,
obj=[obj,MyObj]
In any case, what you're seeing is still somewhat surprising, and I haven't quite figured out what's going on. Because this is a handle class, I would expect the behavior that you're looking to already be there, although note that there is no need to return a copy of "obj" from a handle method. In other words, if you write the function signature this way
function add(obj,...)
that should have been sufficient.
|