Simulink Initial Conditions - Active/Deactive Input and Initial State from MATLAB Script

4 次查看(过去 30 天)
Dear Community,
I was surfing over the web, but i could not find resources that can help me with the following. Also, I am using MATLAB 2022b and launching Simulink simulations from MATLAB using the command:
SimData = sim('Simulinuk_Model.slx','simulationmode','Normal');
However, i want to active and deactive the following options (Input and Initial state check and uncheck) through a matlab script:
Could someone please be so kind to provide me the example code?
Thank you very much in advance

采纳的回答

Sandeep Mishra
Sandeep Mishra 2024-9-23
Hi Rodrigo,
To enable or disable parameters in a Simulink model, you can effectively use the 'set_param' function in MATLAB. This function requires the current configuration set of the Simulink model, along with the specific parameter name and the desired value.
You can refer to the following code snippet to check (‘on’) and uncheck (‘off’) the model parameters:
load_system("simulink_model.slx")
% Fetching current configuration set
cs = getActiveConfigSet('simulink_model');
% To uncheck "Load from workspace" for input data
set_param(cs, 'LoadExternalInput', 'off');
% To uncheck "Load from workspace" for input state
set_param(cs, 'LoadInitialState', 'off');
% Save changes and close the model
save_system('simulink_model');
close_system('simulink_model');
For more information, refer to the following MathWorks documentation:
  1. Configure Model from Command Line’ : https://www.mathworks.com/help/releases/R2022b/rtw/ug/configure-model-from-command-line.html
  2. set_paramfunction: https://www.mathworks.com/help/releases/R2022b/simulink/slref/set_param.html
  3. getActiveConfigSetfunction: https://www.mathworks.com/help/releases/R2022b/simulink/slref/getactiveconfigset.html
I hope this helps you in updating the model parameters.
  1 个评论
Rodrigo
Rodrigo 2024-9-27
Hello Sandeep,
Thank you very much for your response, it worked perfectly.
The only aspect that maybe is no so comfortable is that on the command:
load_system("simulink_model.slx")
the argument is a string, whereas on the commands:
cs = getActiveConfigSet('simulink_model');
save_system('simulink_model');
close_system('simulink_model');
the arguments are chars. This dichotomy is not so comfortable when programming.
Regards
rzgi

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by