From db8eaff7517fa11b9f70f060eb207ae5d8109e00 Mon Sep 17 00:00:00 2001 From: Enrico Lumetti Date: Fri, 6 Dec 2024 23:14:58 +0100 Subject: [PATCH] Add comments for SimulationInput variables/parameters modification --- simulink/rc_simulation_input.m | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/simulink/rc_simulation_input.m b/simulink/rc_simulation_input.m index bb790a7..1bf8742 100644 --- a/simulink/rc_simulation_input.m +++ b/simulink/rc_simulation_input.m @@ -1,7 +1,6 @@ clear; model_name = "rc_circuit"; -load_system(model_name); stopTime = 5; V_in = 10; @@ -14,8 +13,14 @@ ts = (0:timestep:stopTime)'; vs = sin(2*pi*freq * ts); sim_in = Simulink.SimulationInput(model_name); +% Note: the following has effect only if the system mask has been created +% for the settable parameters. +% Using Simulink.Parameter(R) in the above doesn't work. sim_in = sim_in.setModelParameter("R", num2str(R)); -sim_in = sim_in.setModelParameter("C", num2str(C)); + +% for model workspace variables, it's important to specifiy the workspace +% it's not necessary for the variable to be in the mask or to be argument +sim_in = sim_in.setVariable("C", C, Workspace=model_name); sim_in = sim_in.setModelParameter("StopTime", num2str(stopTime)); % note: to be compatible with port size, ts must be a column vector @@ -33,4 +38,4 @@ ylabel('V_{in} (Volt)'); subplot(2, 1, 2); plot(res.yout{1}.Values); -close_system(model_name); \ No newline at end of file +