How can I allow the S-Function parameter field to remain blank without causing Simulink to return an error?

3 views (last 30 days)
I have an S-Function that accepts an empty string parameter. However, if I leave the "S-Function parameters" field blank (on the S-Function block parameter dialog box), Simulink returns the following error:
Invalid expression found in mask parameter.
The expression is an empty string.
I am aware that I can avoid this error by entering an empty string (i.e., ''), but I prefer to leave this field blank when passing an empty string to the S-Function.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
Simulink will not allow S-Functions to execute unless you explicitly specify any applicable parameters in the "S-Function parameters" field on the S-Function block parameter dialog box. Note that leaving this field blank does not signify an empty string.
However, you can achieve the behavior you desire by using a model callback function to identify the blank field and populate it with an empty string (i.e., ''). The callback function must execute before the simulation begins. Consequently, either the "Model Initialization Function" in MATLAB 6.5 (R13) or the "InitFcn" in MATLAB 7.0 (R14) and later versions is appropriate for this task. You will need to follow the steps below to construct this simple callback function.
1. Open the model.
2. Click on "File -> Model Properties".
3. Click on the "Callbacks" tab in the Model Properties dialog box.
4. In the "Model Initialization Function" (R13) or "InitFcn" (R14) edit box, enter the following MATLAB commands:
if isempty(get_param('modelname/SFunction', 'Parameters'))
set_param('modelname/SFunction', 'Parameters', '''''');
end
In the preceding, "modelname/SFunction" represents the path of the S-Function block in your model.

More Answers (0)

Categories

Find more on Introduction to Installation and Licensing 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!