书籍:Matlab实用教程
工具:Matlab2021a
电脑信息:Intel® Xeon® CPU E5-2603 v3 @ 1.60GHz
系统类型:64位操作系统,基于X64的处理器 windows10 专业版
第7章 simulink仿真环境
7.7 用MATLAB命令创建和运行simulink模型
7.7.1 用MATLAB命令创建simulink模型
1、simulink模型与文件
cpp
>> new_system('Ex0711model')
>> open_system('Ex0711model')

cpp
>> new_system('Ex0711model')
>> open_system('Ex0711model')
>> save_system('Ex0711model','Ex0711')
>> close_system('Ex0711model',1)
警告: There is no system named 'Ex0711model' to close. You can disable this warning by using 0 as the second argument in the close_system command.
> 位置:close_system
>> close_system('Ex0711',1)
关掉模块。
2、添加模块和信号线
cpp
>> open_system('Ex0711')
>> add_block('built-in/Step','Ex0711/Step','position',[20,100,40,120])
>> add_block('built-in/Sum','Ex0711/Sum','position',[60,100,80,120])
>> add_block('built-in/Transfer Fcn','Ex0711/Fcn1','position',[120,90,200,130])
There is no block named 'built-in/Transfer Fcn'

cpp
>> add_block('built-in/Scope','Ex0711/Scope','position',[240,90,260,120])
>> add_line('Ex0711','Step/1','Sum/1')
>> add_line('Ex0711','Step/1','Sum/2')
>> add_line('Ex0711','Sum/3','Scope/1')
Invalid Simulink object name: Sum/3.

找不到Fcn模块,Sum也链接不到scope
3、设置模型和模块属性

cpp
>> h=gcs
h =
'Ex0711'
cpp
>> set_param('Ex0711','StopTime','15')
>> set_param('Ex0711/Step','time','0')
>> set_param('Ex0711/Sum','Inputs','+-')

4、删除模块额信号线
delete_block('Ex0711/Scope')
delete_line()
7.7.2 用MATLAB命令运行simulink模块
cpp
>> y=sim('Ex0711',[0,15])
警告: 'Input Port 1' of 'Ex0711/Scope' is not connected.
警告: 'Output Port 1' of 'Ex0711/Sum' is not connected.
警告: Source 'Ex0711/Step' specifies that its sample time (-1) is back-inherited. You should explicitly specify the sample time of sources. You can disable this diagnostic by setting the 'Source block specifies -1 sample time' diagnostic to 'none' in the Sample
Time group on the Diagnostics pane of the Configuration Parameters dialog box.
y =
Simulink.SimulationOutput:
tout: [52x1 double]
SimulationMetadata: [1x1 Simulink.SimulationMetadata]
ErrorMessage: [0x0 char]