3

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Entropy
  • 63
  • 6

1 Answers1

2

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.

  • That makes a lot of sense. I wasn't thinking about the possibility of having multiple copies, since that's not currently a concern for my application. Thanks for the information. – Entropy Mar 09 '11 at 21:42