Apologies if this has been asked before, I have not been able to find any similar questions on Matlab Central or any other site.
Say I have a variable, and I store this variable as AppData. If I go modify the variable after storing it as appdata, it will not change the appdata.
>> number = 0;>> setappdata(0,'NumberStorage',number)>> number = 10;>> getappdata(0,'NumberStorage')ans = 0
Say I have a class, defined as follows:
classdef SampleClass < dynamicprops properties testValue = 0; endend
If I create an instance of this class and store it as appdata and then modify it after the fact, it does change the appdata.
>> object = SampleClass;>> object.testValue = 0;>> setappdata(0,'ObjectStorage',object)>> object.testValue = 10;>> getappdata(0,'ObjectStorage')ans = SampleClass with properties: testValue: 10
My question is, why does this happen? And how can I prevent it from happening?
Best Answer