
4.4.2 实例——矩阵运算

本实例演示矩阵的运算。
操作步骤如下。
1.创建模型文件
在MATLAB“主页”主窗口选择“新建”→“Simulink Model(仿真模型)”命令,打开Simulink模型文件。
2.打开库文件
选择功能区中的“Library Browser(模块库浏览器)”命令,弹出如图4-25所示的“仿真模块库浏览器”窗口。
3.模型保存
选择“SIMULINK(仿真)”功能区中的“Save As(另存为)”命令,将生成的模型文件保存为Matrix1.slx。
4.放置模块
选择“Simulink(仿真)”→“Math Oper-ations(数学运算)”模块库中的“Matrix Con-catenate(串联矩阵)”“Product of Elements(元素求和)”“Reshape(矩阵变维)”模块,将其拖动到模型中,用于矩阵运算。
在模块库中搜索“Constant(常数)”“Display(显示器)”模块,将其拖动到模型中,用于显示输出结果。
5.模块参数设置

图4-25 “Simulink Library Browser(仿真模块库浏览器)”窗口
双击模块,即可弹出对应的模块参数设置对话框,用于设置对应参数。
◆ Constant模块参数设置。Constant value(常量值)设置如图4-26所示。
◆ Constant1模块参数设置。Constant value(常量值)设置如图4-27所示。
◆ Display模块参数设置。Decimation设置为“2”,如图4-28所示。
6.模块连接
进行模块端口连接,在功能区“FORMAT(格式)”选项卡下单击“Auto Arrange(自动布局)”按钮,对连线结果进行自动布局,最终结果如图4-29所示。

图4-26 Constant模块参数设置

图4-27 Constant1模块参数设置

图4-28 Display模块参数设置

图4-29 模块连接结果
7.运行仿真
根据模型系统完成参数设置后,单击“Run(运行)”按钮,在显示器中显示运行结果,仿真结果如图4-30所示。

图4-30 运行结果