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

4 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Bill Tubbs
Bill Tubbs il 13 Feb 2022
Modificato: Bill Tubbs il 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;

Più risposte (1)

Benjamin Thompson
Benjamin Thompson il 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 Commenti
Bill Tubbs
Bill Tubbs il 13 Feb 2022
Modificato: Bill Tubbs il 13 Feb 2022
I've added the observer to the mask as a parameter and I can now access it in the icon script:
Mask now looks like this:
Now I can use this in the icon script:
disp(obs.label)
However, this obs parameter is now not being passed to the S-function! (somehow the original parameter value is being passed).
Benjamin, you state above that "you can pass those mask variables to your S-Function in the parameters list."
I'm not sure how exactly. My S-function is currently using this method (described here):
% Get observer struct
obs = block.DialogPrm(1).Data;
B.t.w. Is there a tutorial on how to make a mask for an s-function block? I can't find one.
Bill Tubbs
Bill Tubbs il 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.

Accedi per commentare.

Categorie

Scopri di più su Event Functions in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by