cannot update class definition in Matlab

后端 未结 2 982
温柔的废话
温柔的废话 2021-01-06 09:31

I am running into an infuriating problem with Matlab, and an earlier answer to apparently the same problem didn\'t help me, unfortunately. I apologize that the question is

2条回答
  •  隐瞒了意图╮
    2021-01-06 10:10

    You have an intermediate instance myClass.father that is not being destroyed by MATLAB. You have to deleteit yourself

    >> clear grandpa
    >> delete(son.precursors{1})
    >> clear son
    >> clear classes
    >> son = myClass.son
    son = 
        son    
    >> sumVal(son)
    ans =
         6
    

    Edit: Alternatively, you can add a destructor to your class

        function delete(obj)
            if isa(obj.precursors{1}, 'myClass')
                delete(obj.precursors{1});
            end
        end
    

    and use delete(son) instead of leaving it to clear function to destroy. You can extend this to your case and recursively delete all instances in your tree.

提交回复
热议问题