nispio
nispio

Reputation: 1744

Add a Simulink block to set system-wide parameters

I have a Simulink model with a number of system-wide parameters that affect many different blocks. The way I deal with this right now is by encapsulating the entire model inside of a masked subsystem at the top level and managing the parameters there. Doing this makes the parameters visible to all blocks. However, I would rather have my model reside at the top level and include a parameters block there that I can use to manipulate the system parameters.

I don't know if pictures will help here, but they can't hurt:

Nested model

The picture above shows an example of my current setup. Notice that the entire design is nested inside of a masked subsystem called "System Parameters"

Parameters as top-level block

This picture shows how I would like for the top level to appear. This seems to be a much more intuitive interface. It would also allow for much easier copying of my parameters block between models, which is my main interest in it. I would really like to convert it to a library block that I can use in a handful of models that are based on the same hardware system. However, the problem is that the parameters within the System Parameters block are not visible to the rest of the blocks in the model (at least not directly).

Is there a way that a block like the one in the second image could make its parameters easily available to the rest of the model?

Upvotes: 0

Views: 916

Answers (1)

am304
am304

Reputation: 13886

For the parameters to be available to the other blocks, they need to be either in the model workspace or in the base workspace. You could add an initialise callback to your block that would copy the mask parameters to either workspace, but in my opinion, a much better practice would be to have a MATLAB script defining all the parameters in the base workspace that is called during the InitFcn model callback. You then just need to distribute that MATLAB script along with your model for the end user.

Upvotes: 2

Related Questions