1

I have a MATLAB Function block wrapped in a masked subsystem. The subsystem's mask has a parameter p1 which I want to use inside the MATLAB function. How to do this manually is described in the documentation. However, I need to do this programmatically and so far I've failed to figure out how to do this.

Adding the parameter to the subsystem's mask programmatically is easy using Simulink.Mask.addParameter, as is creating the MATLAB Function block and setting its code. The hard part is to programmatically switch the scope of the function argument p1 from "Input" to "Parameter" (Steps 2-4 in the documentation). I couldn't find where this information is stored (I checked both the "traditional" Simulink block parameters and the Stateflow object associated with the block).

0

1 Answer 1

4

I found the answer on MATLAB Answers. Use the following code to set the scope of input number i to Parameter:

% Get Stateflow root object
S = sfroot();

% Get block handle
B = S.find('Name','myBlockName','-isa','Stateflow.EMChart');

% Set scope
set(B.Inputs(i), 'Scope', 'Parameter')

Note that you can use B.getChildren() to access all inputs, outputs and parameters of the block. This is especially useful for parameters, since there is no separate B.Parameters list (as opposed to B.Inputs and B.Outputs).

Sign up to request clarification or add additional context in comments.

1 Comment

Be careful using this. It will work if simulink model is running using matlab, but it will not work if you compile the model using simulink coder in order to create a executable model

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.