1
votes

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).

1
I don't think that's possible, or if it is, it's not documented as you have found out. The following is somewhat related mathworks.co.uk/matlabcentral/newsreader/view_thread/285859.am304

1 Answers

4
votes

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).