|
Assume that you have a model called 'untitled' and a constant block in it 'Constant' where the value is given my the variable C, then in your S-Function you'll want
assignin('base','C',whateverItsNewValueIs);
set_param('untitled/Constant','Value','C');
Note that the set_param command is not actually changing anything in the block; the parameter was C at initialization and it will be after the set_param, however by doing a set_param you are forcing the block to go back to the workspace to get the current value for C.
Or if it's a Gain block called 'nameOfMyBlock' with variable K as the gain value you'll want
assignin('base','K',whateverItsNewValueIs);
set_param('untitled/nameOfMyBlock','Gain','K');
In general you'll have
set_param('modelName/SubsystemName/SubSubsystemName/BlockName','BlockProperty',NewValue);
You can get the block properties in the doc from the section
Simulink->Model And Block Parameters->Block Specific Parameters
It looks like for an Fcn block you'll want
set_param('untitled/nameOfMyBlock','Expr','theExpression');
Note that not all parameters of a block are tunable.
I might also add that what you are doing here is an unusual thing to want to do, and my suspician is that you are tying to do something that would be better achieved by rewriting your model so that the value of a signal is changing and that signal is used to update how a block works.
My suspicions are even more highlighted when you say you're using an Fcn block, which is one that I don't recommend -- it's typically used by people who haven't spent time thinking about how to implement their algorithm in a better way.
With that, good luck...
Phil.
|