I am trying to copy a Simulink.SimulationInput object by doing the following: Input(1) = Simulink.SimulationInput('foo'); Input(1) = Input(1).setVariable('A',Simulink.Parameter(5)); Input(1) = Input(1).setVariable('simin',timeseries([0,10],[0,10])); %% Input(2) = Input(1); Input(2) = Input(2).setVariable('A.Value',10); %% Input(1).Variables(1).Value Input(2).Variables(1).Value By setting the value of variable 'A' to 10 after copying Input(1) to Input(2), the value for Input(1) also changes to 10. Why does this happen? Is there a deep copy method for SimulationInput object?
Kshitij Singh answered .
2025-11-20
Input(1) = Simulink.SimulationInput('mdlname');
Input(1) = Input(1).setVariable('A',Simulink.Parameter(5));
Input(1) = Input(1).setVariable('simin',timeseries([0,10],[0,10]));
%%
Input(2) = Input(1);
Input(2) = Input(2).setVariable('A',Simulink.Parameter(10));
%%
Input(1).Variables(1).Value
Input(2).Variables(1).Value
2.Create Simulink Parameter and SimulationInput object first, then use setVariable:
Input(1:2) = Simulink.SimulationInput('mdlname');
A = Simulink.Parameter(5);
Input(1) = Input(1).setVariable('A', A);
Input(1) = Input(1).setVariable('simin',timeseries([0,10],[0,10]));
%%
Input(2) = Input(2).setVariable('A.Value', 10);