开发者

Simulink and MATLAB - When to use a workspace variable vs inport/outport

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 t开发者_开发技巧he 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜