pass a parameter to a masked subsystem

5 views (last 30 days)
Tomaso Poggi
Tomaso Poggi on 10 Oct 2011
Hi, I am using Simulink to model a dynamical system.
My system is composed of many subsystem, whose behaviour depends on some parameters (cut-off frequency, amplitude, gain, etc.). All my subsystems are blocks collected in a library.
I would like to set the values of the parameters of the inner blocks inside each subsystem. I am trying to do the following: - Create a mask for each block (done) - Calculate the value of the block parameters depending on the value of the mask parameter (here is where I have got problems).
I supposed that this could be done by creating variables in the initialization tab of the Mask Editor, but I cannot do that.
Any suggestion?
Thank you

Answers (2)

Kaustubha Govind
Kaustubha Govind on 10 Oct 2011
You can set some initial values on the variables from the Initialization pane, but I think the right place for you to put the code might be in the "Dialog Callback" textbox that each parameter has. This will ensure that if the user changes one of the mask parameter values, your dependent variables are also re-calculated.
Also, refer to the documentation on Creating a Block Mask for more information.
  3 Comments
Kaustubha Govind
Kaustubha Govind on 10 Oct 2011
You're right. Sorry, it looks like the Initialization pane is indeed the right place to create the variables, since it is run at the start of every simulation (so even if the user changes the parameters, that will be account for before simulation starts). Why are you unable to do so?
Tomaso Poggi
Tomaso Poggi on 11 Oct 2011
Please, see the answer to Doug Eastman's post

Sign in to comment.


Doug Eastman
Doug Eastman on 10 Oct 2011
Here are two options:
1. Calculate the derived values directly in the blocks that need them in the subsystem. For example, maybe a gain block needs the mass, but all you have is the density and volume, simply enter the gain as 'density*volume'. This is the easiest but may not be the best if you have a complex expression that is used in many blocks in the subsystem.
2. Calculate the value in the initialization pane. E.G. 'mass=density*volume'. Then you can use mass directly in the gain block.
  1 Comment
Tomaso Poggi
Tomaso Poggi on 11 Oct 2011
Option 1: it works but, as you have pointed out, it is not the best when dealing with long expressions.
Anyway, it does not work if I have to set a nontunable parameter, such as the sampling time of a discrete time system. In this case the error "Model arguments can not be used in non-tunable expressions" is reported.
2. The initialization pane seems to be useless: every value or expression I put in it is ignored.
I used the "Dialog Callback" textbox that each parameter has but it has two major drawbacks: i) expressions are evaluated only when the parameter is changed (and not at simulation startup); ii) expressions create global variables.
Thank you for your help.
It seems so strange to me that there is no easy way to create your own custom blocks in Simulink and put them in a library.
It is like a programming language that does not hallow you to create functions!!!
Maybe I am trying to do that in the wrong way.
Any suggestion is appreciated.

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!