Simulink 和 MATLAB - 何时使用工作区变量与输入/输出端口
我是 Simulink 的新手,并且一直在创建一些具有大约五个输入和五个输出的模型/库。据我所知,我可以从工作区读取变量并将其写入库中的工作区,或者我可以使用输入端口和输出端口来完成相同的操作。
一种方法通常比另一种方法更好吗?我认为每个都有其优点和缺点,但我还没有发现它们。
I'm new to using Simulink, and have been creating some models/libraries that have roughly five inputs and five outputs. As far as I can tell, I can read a variable from the workspace and write it to the workspace in my library, or I can use inports and outports to accomplish the same thing.
Is one method generally better than the other? I assume each has its advantages and disadvantages, but I haven't discovered them yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这类似于在进行 m 文件编程时决定使用函数还是脚本。以输入/输出为接口的模型就像一个函数,它定义了输入和输出。
我倾向于以类似于我的 m 文件程序的方式构建 simulink 模型。大多数模型都类似于函数。它们的所有 I/O 都有输入端口和输出端口。这种方法的好处是这些模型可以在其他环境中重复使用。您还可以稍后决定拥有这些模型的多个副本,如果所有 I/O 都使用相同的工作区变量,则这会变得更困难。
有时,子模型需要一些在整个模型中通用的数据,对于这些值,我确实使用工作区变量。我尝试将其保留为全局常量。
我创建了一个顶级模型,它使用可以直接从工作区或磁盘上的文件读取的数据来调用子模型。重点是,一旦子模型被定义为函数,您就可以自由地以各种方式构建顶层,这些方式可以随着开发的进展而演变。
This is similar to deciding whether to use a function or a script when doing m-file programming. A model with inport/outports as its interface is like a function, which has defined inputs and outputs.
I tend to structure simulink models similarly to my m-file programs. Most models are like functions. They have inports and outports for all of their I/O. The benefit of this approach is that those models can be re-used in other contexts. You can also decide later to have multiple copies of those models, which gets harder to do if all of the I/O goes the same workspace variables.
Sometimes the sub-models require some data that is common throughout the model, and for those values I do use workspace variables. I try to reserve this for global constants.
I create a top-level model that calls the sub-models using data that may be read directly from the workspace, or from files on disk. The point being, once the sub-models are defined as functions, you are free to structure the top level in various ways that can evolve as development progresses.