提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
通过.m的命令控制simulink的开始、暂停、步进;
一、set_param()介绍
以下使Matlab2020b中的文档对set_param()的介绍:
set_param(Object,ParameterName,Value,…ParameterNameN,ValueN) sets the parameter to the specified value on the specified model or block object.
When you set multiple parameters on the same model or block, use a single set_param command with multiple pairs of ParameterName, Value arguments, rather than multiple set_param commands. This technique is efficient because using a single call requires evaluating parameters only once. If any parameter names or values are invalid, then the function doesn’t set any parameters.
Tips:
If you make multiple calls to set_param for the same block, then specifying the block using a numeric handle is more efficient than using the full block path. Use getSimulinkBlockHandle to get a block handle.
If you use matlab -nodisplay to start a session, you cannot use set_param to run your simulation. The -nodisplay mode does not support simulation using set_param. Use the sim command instead.
After you set parameters in the MATLAB® workspace, to see the changes in a model, update the diagram.
set_param(model,‘SimulationCommand’,‘Update’)
二、通过set_param()命令控制simulink模型运行
1.开始、暂停、步进
代码如下(示例):
set_param('.mdl的名称(不加.mdl尾缀)','SimulationCommand','start')
set_param('.mdl的名称(不加.mdl尾缀)','SimulationCommand','pause')
set_param('.mdl的名称(不加.mdl尾缀),'SimulationCommand','step')
举个栗子吧,例如当前有个test.mdl的模型,想通过在.m脚本中写命令使test.mdl开始运行、暂停运行、步进一步后暂停;
set_param('test','SimulationCommand','start')
set_param('test','SimulationCommand','pause')
set_param('test','SimulationCommand','step')