How to add a parameter value to the icon of an S-function block

8 views (last 30 days)
I'm new to S-function blocks in Simulink but I've made a working S-function block and now I want to display a value on its icon.
Right now, my Icon & Ports script looks like this:
However instead of the text 'MKF' being static, I want it to display a string from my first parameter:
disp(block.DialogPrm(1).Data.label)
Obviously this doesn't work. This is how you access parameters from within the S-function m-file.
How can I get the same variable from my S-function parameter to the icon script?
I looked in the Parameters & Dialog menu tab and it looks like this:
Does one of these contain my parameter?

Accepted Answer

Bill Tubbs
Bill Tubbs on 13 Feb 2022
Edited: Bill Tubbs on 13 Feb 2022
Based on the comments in response to Benjamin's answer, here is the complete and concise answer to the question:
  1. First create a mask for the block. Right click on the block and select Mask > Edit Mask.
  2. Add the parameters you want to the mask in the Parameters & Dialog tab, in my case just one parameter called 'obs':
3. Now you can use these parameters in the Icon & Ports script. For example:
disp(obs.label)
4. And when the user double-clicks on the block they will be able to specify the parameters:
4. Finally, right click on the block and select Mask > Look Under Mask. Now add the parameters you want to pass to the S-function as a list of comma-separated names. In my case, just the one parameter 'obs':
Presumably, now the 'obs' reference is to the block's own parameter rather than an object in the MATLAB workspace as it would have been before you defined 'obs' in step 2 above.
5. These parameter(s) will now be accessible to the S-function in the usual way. For example:
% Get observer struct
obs = block.DialogPrm(1).Data;

More Answers (1)

Benjamin Thompson
Benjamin Thompson on 10 Feb 2022
In the Icon and Ports tab, set Run initialization to on, then anything you define in the mask workspace in the Initialization tab can be used in your drawing and display commands in Icon and Ports. See the MATLAB documentation "Mask Editor Overview" for more information. In the Initialization tab you can use the get_param commands to get parameter values.
Alternatively, use Block Annotations. Right click on a block and go to properties. Any parameters you created in your mask will also be available there for display, but it will be above or below the block rather than inside.
  9 Comments
Bill Tubbs
Bill Tubbs on 13 Feb 2022
Finally figured it out! I found the answer to the last bit here.
As well as editing the mask to add your parameter to it, you need to select the "Look under mask" menu option (right click on block and look in Mask menu). This shows the default S-function mask, where you can now add the mask parameters which will be passed to the S-function:
For the benefit of others, I think I should write a concise explanation of the complete answer as a separate answer.

Sign in to comment.

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by