How can I pass a string argument as a parameter through my masked subsystem?

2 views (last 30 days)
How can I pass a string argument as a parameter through my masked subsystem? In Simulink, I want to use a block within a subystem that has a string argument.
This includes blocks such as the Fcn, MATLAB Fcn, Goto, From, To Workspace, From Workspace, To File, From File, S-function blocks.
As an example, let us refer to the From block. I wanted to have the signal that this block refers to entered into the Mask. I tried creating a variable in the mask workspace named from_signal and assign its value to literal.
Then, in the From block in my subsystem, I entered from_signal.
In the mask dialog, I enter the actual name of the signal as signal1. Therefore, the assignment, should be in the mask workspace from_signal = 'signal1'.
When I run the model, the From block is looking for a signal named from_signal, and not signal1. Why is it not recognizing this assignment?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Nov 2009
Using this kind of syntax will not work with any of the blocks that expect strings in their dialogs. This is because Simulink will think that you are referencing the actual string entered (in the example above from_signal), and not the variable it is referencing.
To get around this, set the value of the string using the SET_PARAM command in the Mask Initialization. For the example above, place the following line in the Mask Initialization commands:
set_param('modelname/subsystemname/blockname', 'GotoTag', from_signal)
This command will change the actual string placed into the block through the mask. For more on the exact syntax and available properties for SET_PARAM, see Appendix A of Using Simulink.

More Answers (0)

Categories

Find more on Author Block Masks 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!