How do I copy a Simulink Parameter Object by value in Simulink?
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 27 de Jun. de 2009
Editada: MathWorks Support Team
el 24 de Abr. de 2014
I have a Simulink Parameter Object, and I would like to copy this variable by value. When I execute the following code, I note that the copy I make using the "=" (equals) operator is actually a copy by reference:
a=Simulink.Parameter; % create a parameter object
a.Value=5; % set a value
b=a; % copy by reference
b.Value=10; % change the value in the copy
% Now, note that the value in the original has also changed.
a.Value
Respuesta aceptada
MathWorks Support Team
el 18 de Oct. de 2013
In order to create a new Simulink Parameter Object from an existing one, use the "copy" method when using MATLAB R2012a or later.
The following code creates a copy by value of a Simulink Parameter object.
a=Simulink.Parameter; % create a parameter object
a.Value=5; % set a value
b=a.copy; % use copy
b.Value=10; % change the value in the copy
% Now we notice that the original value has not changed:
a.value
If you are using MATLAB versions prior to R2012a, please use "deepCopy" rather than "copy".
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!