Rank: 476526 based on 0 downloads (last 30 days) and 0 file submitted
photo

Shaw

E-mail

Personal Profile:

 

Watch this Author's files

 

Comments and Ratings by Shaw View all
Updated File Comments Rating
17 Nov 2011 Clone Handle Object - using MATLAB OOP How to clone an object (deep copy) which inherits reference behaviour from the 'handle' class. Author: Bobby Nedelkovski

for a handle class contains another handle object. I would do deep copy "recursively". (the following one might face the loop situation.)

classdef B < handle
properties
a % A obj
end
methods
function this = B()
this.a = A();
end

% class A should have the SIMILAR
% clonePublic function
function newObj = clonePublic(this)
props = properties(this);
newObj = B();
for i = 1: length(props)
tmp = this.(props{i});
if(isa(tmp,'handle'))
newObj.(props{i}) = tmp.clonePublic();
else
newObj.(props{i}) = tmp ;
end
end
end
end
end

17 Nov 2011 Clone Handle Object - using MATLAB OOP How to clone an object (deep copy) which inherits reference behaviour from the 'handle' class. Author: Bobby Nedelkovski

test

Contact us