crobar
crobar

Reputation: 2939

How to use structure as parmeter for simulink subsystem and use fields inside as block parameters?

I have created a subsystem in Simulink. I would like this subsystem to have a single parameter, which is supposed to be a Matlab structure. Inside the subsystem, I would then like parameters of some of the blocks to be the fields of this structure.

So for example, imagine the subsystem has a single parmeter sys_inputs, then inside the subsystem I have two Constant blocks and the value for the first Constant block should be sys_inputs.Constant1, and the other should be sys_inputs.Constant2.

Is this possible, and if so, how exactly?

I'm finding the Matlab documentation on passing mask parameters to subsystem internal blocks a bit obtuse.

The purpose is so that the user only has to provide a single parameter to the subsystem instead of changing many parameters, when this input usually comes pre-packaged as a structure.

Upvotes: 0

Views: 2753

Answers (1)

crobar
crobar

Reputation: 2939

I discovered the answer myself.

  1. First create the subsystem

  2. Right click and 'create mask'

  3. Edit mask parameters

mask parameters tab

  1. Add an 'edit' parameter. The 'Name' of this parameter will be the variable name you can use inside your subsystem, e.g. sys_inputs

  2. Inside the subsystem, you can use the sys_inputs parameter as though it was a workspace variable, so you can enter things like sys_inputs.Constant1 in the subsystem components parameters

Upvotes: -1

Related Questions