Is there an example that demonstrates how to access parameters located in an S-function mask from within an S-function in Simulink?

26 views (last 30 days)
I wrote a Simulink S-function that requires user-entered parameters. I masked this S-function to allow the user to input the necessary parameters in the mask dialog. However, it is not clear to me how to use those parameters from within my S-function code.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
In order to enter parameters into an S-function, the parameters are specified in a list in the S-function block’s “S-function parameters” prompt. When an S-function is masked, the inputs into this prompt have access to any of the variables in the mask workspace. Thus, to use the mask inputs as inputs into the S-function, you must properly enter the mask workspace variables into the S-function block’s “S-function parameters” prompt.
There are many examples of this in the S-function demos. One such example is the Matrix Addition demo, which can be accessed by entering the following at the MATLAB Command Prompt:
sfcndemo_matadd
In this demo, the S-function (sfun_matadd.c) is masked so that the number to be added to the input is entered in the mask dialog under the “Operand 1” prompt. By right clicking on the S-function and selecting “Edit Mask”, you can see that the mask variable that corresponds to the “Operand 1” prompt is called “Operand”. Now, if you were to look under the mask (by right clicking the S-function and selecting “Look under Mask”), you would see that the variable “Operand” is entered as the first parameter into the S-function in the “S-function parameters” prompt. This works because the S-function has access to the variables in the mask workspace.
More information on masks and the mask workspace can be found in the documentation at the following locations:
Simulink 4.1 (R12.1) => Simulink > Using Simulink > Using Masks to Customize Blocks
Simulink 5.0 (R13) and Simulink 6.0 (R14) => Simulink > Using Simulink > Creating Masked Subsystems

More Answers (0)

Categories

Find more on Block and Blockset Authoring in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!