Add comments for SimulationInput variables/parameters modification

This commit is contained in:
Enrico Lumetti 2024-12-06 23:14:58 +01:00
parent 7f93745d2f
commit db8eaff751
1 changed files with 8 additions and 3 deletions

View File

@ -1,7 +1,6 @@
clear; clear;
model_name = "rc_circuit"; model_name = "rc_circuit";
load_system(model_name);
stopTime = 5; stopTime = 5;
V_in = 10; V_in = 10;
@ -14,8 +13,14 @@ ts = (0:timestep:stopTime)';
vs = sin(2*pi*freq * ts); vs = sin(2*pi*freq * ts);
sim_in = Simulink.SimulationInput(model_name); 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("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)); sim_in = sim_in.setModelParameter("StopTime", num2str(stopTime));
% note: to be compatible with port size, ts must be a column vector % 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); subplot(2, 1, 2);
plot(res.yout{1}.Values); plot(res.yout{1}.Values);
close_system(model_name);