MATLAB/Simulink (2):使用 get_param、set_param 实现 Simulink 模块参数的配置

找出参数的脚本名称是重点,因为模型中显示的参数名称并非参数的脚本名称。

1.模块对话框参数的修改

在这里插入图片描述

模块对话框参数
(1)获取模块对话框参数名称

DialogParameters = get_param('Test/Gain', 'DialogParameters');

工作区得到以下结果:
在这里插入图片描述
DialogParameters 包含了所有模块对话框参数的属性,包括 Prompt、Type、Enum、Attributes,其中 Prompt 的值就是对话框参数的显示名称。
在这里插入图片描述
(2)修改对话框参数
使用 set_param 修改对话框参数。

set_param('Test/Gain', 'SaturateOnIntegerOverflow','on');

修改后的结果:
在这里插入图片描述

2.模块普通参数的修改

比如修改模块的优先级。
在这里插入图片描述
在这里插入图片描述
(1)获取参数名称

ObjectParameters =get_param('Test/Gain','ObjectParameters');

在这里插入图片描述
因为参数很多(一般都有一两百个),所以查找起来比较麻烦。我目前用的方法是只生成参数名称,然后复制到 Excel 进行搜索。如下:

ObjectParameters =fieldnames(get_param('Test/Gain','ObjectParameters'));

在这里插入图片描述
(2)修改参数值

set_param('Test/Gain', 'Priority','1');

将优先级设置为1,结果如下:
在这里插入图片描述
备注:可以找到模型中同一种类型的模块,从而进行多个模块的属性修改。

blockList = find_system('Test','BlockType','FromWorkspace');
for ii = 1:length(blockList)
	set_param(blockList{ii},'Interpolate','off');
end
  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
For a useful introduction that will help you start using Simulink quickly, take a look at “Running a Demo Model” in Chapter 2. Browse around the model, double-click on blocks that look interesting, and you will quickly get a sense of how Simulink works. If you want a quick lesson in building a model, see “Building a Simple Model” in Chapter 2. Chapter 3 describes in detail how to build and edit a model. It also discusses how to save and print a model and provides some useful tips. Chapter 4 describes how Simulink performs a simulation. It covers simulation parameters and the integration solvers used for simulation, including some of the strengths and weaknesses of each solver that should help you choose the appropriate solver for your problem. It also discusses multirate and hybrid systems. Chapter 5 discusses Simulink and MATLAB features useful for viewing and analyzing simulation results. Chapter 6 discusses methods for creating your own blocks and using masks to customize their appearance and use. Chapter 7 describes subsystems whose execution depends on triggering signals. Chapter 8 provides reference information for all Simulink blocks. Chapter 9 provides information about how Simulink works, including information about zero crossings, algebraic loops, and discrete and hybrid systems. Chapter 10 provides reference information for commands you can use to create and modify a model from the MATLAB command window or from an M-file. Chapter 11 explains how to use the Simulink debugger to debug Simulink models. It also documents debugger commands. Appendix A lists model and block parameters. This information is useful with the get_param and set_param commands, described in Chapter 10. Appendix B describes the format of the file that stores model information. Although we have tried to provide the most complete and up-to-date information in this manual, some information may have changed after it was completed. Please check the Known Software and Documentation Problems delivered with your Simulink system, for the latest release notes.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值