You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the MOST object opt_model is a handle class
that is, if you say: mdi2.om = mdi.om;
and change something on mdi2.om, you'll notice that the same change happened on mdi.om
that's because mdi2.om and mdi.om are just handles, that point MATLAB to the same 1 object in matlab's memory.
this can be annoying.
now consider this case:
you've already built mdi without solving it, i.e:
After that, any changes you carry out on mdo1 are going to affect mdo0 as well
that's because inside MOST.m, for the case when most.build_model = 0, most.solve_model = 1;
we fixed that old bug by saying: om = mdi.om;
Mathworks introduced a new method for handle classes to allow creating independent duplicates of a handle class. This is only in recent versions of matlab. the command would look like: mdi2.om = copy(mdi.om);
back to MOST.m code, instead of om = mdi.om;
we can: om = copy(mdi.om); to isolate the two objects.
using the copy(handle_class) method requires making a very small change on the class definition
in opt_model, instead of: classdef opt_model < handle
it should be: classdef opt_model < matlab.mixin.Copyable % this here was handle. handle classes can NOT be copied
The text was updated successfully, but these errors were encountered:
the MOST object
opt_model
is a handle classthat is, if you say:
mdi2.om = mdi.om;
and change something on
mdi2.om
, you'll notice that the same change happened onmdi.om
that's because
mdi2.om
andmdi.om
are just handles, that point MATLAB to the same 1 object in matlab's memory.this can be annoying.
now consider this case:
you've already built
mdi
without solving it, i.e:after that, you did some changes on
mdo0
, (added user-defined functions and variables), and proceeded to buildmdo1
:mdo1 = most(mdo0,mpoption(most_opts,'most.build_model',0,'most.solve_model',1));
After that, any changes you carry out on mdo1 are going to affect mdo0 as well
that's because inside MOST.m, for the case when
most.build_model = 0, most.solve_model = 1;
we fixed that old bug by saying:
om = mdi.om;
Mathworks introduced a new method for handle classes to allow creating independent duplicates of a handle class. This is only in recent versions of matlab. the command would look like:
mdi2.om = copy(mdi.om);
back to MOST.m code, instead of
om = mdi.om;
we can:
om = copy(mdi.om);
to isolate the two objects.using the
copy(handle_class)
method requires making a very small change on the class definitionin
opt_model
, instead of:classdef opt_model < handle
it should be:
classdef opt_model < matlab.mixin.Copyable % this here was handle. handle classes can NOT be copied
The text was updated successfully, but these errors were encountered: