Matlab redfining properties for all instances of a class
Show older comments
I have a class I am working on that evaluates functions then uses some criteria to optimize those functions. I created a class for all of this. Everything seems to be working fine except the function that is supposed to drill down to the best answer. Below is an example of what it is doing:
A.get_cases
ans =
1 11 111 121 1211 1221 1321 1331
>> B=drilldown(A, 1)
B =
TRON handle with no properties.
Methods, Events, Superclasses
>>
>> A.get_cases
ans =
1331
So it is redifining the properties of A even though the function only operates on B. What it does to B is just fine, but I do not understand why it is changing properties of A as well. Anyone know why this is happening and how to stop it?
I have included the function below. Any help would be greatly appreciated.
function new_instance=drilldown(old_instance, whichcase)
new_instance=old_instance; %I was hoping the changes would only be to new_instance, but they
% appear to be happening to old_instance as well.
thesemaxes=new_instance.get_maxes{whichcase};
thesemins=new_instance.get_mins{whichcase};
newranges=cell(1,length(thesemaxes));
for i=1:length(thesemaxes)
thisdiff=thesemaxes(i)-thesemins(i);
thisinterval=thisdiff/10;
thisrange=thesemins(i):thisinterval:thesemaxes(i);
newranges{i}=thisrange;
end
indnames=new_instance.get_indnames;
new_instance.set_indvars(indnames, newranges); %This is the only step in the function that
%changes properties of an object from my class.
end
Accepted Answer
More Answers (0)
Categories
Find more on Subclass Definition in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!