MATLAB: How to adjust the “Code Generation” pane in the simulink configuration parameters programmatically

code generationconfiguration parametersMATLABprogrammaticallys-functionsimulink

Hi everybody, I try to generate a Simulink S-Function programmatically. For this I have to adjust some properties in the Simulink configuration parameters from a MATLAB script. So far it is no problem, but I can not adjust the target specific options. I have to make sure that the "Code Generation->S-Function Target->Create new model" checkbox is enabled (see picture on left side). But this pane is not available, if I have changed the system target file before (see picture on rigth side). For example I have changed the system target file programmatically from "grt.tlc" to "rtwsfcn.tlc" and there is no "S-Function Target" pane. When I adjust it by hand, it works.
So how can I refresh the "Code Generation" pane after changing the system target file?
Thanks in advanced!!
(MATLAB R2015b)

Best Answer

I have found a solution myself.
The problem was that I have used the wrong function to adjust the system target file.
Wrong:
set_param('model_name', 'RTWSystemTargetFile', 'rtwsfcn.tlc');
Correct:
configSet = getActiveConfigSet('model_name');
switchTarget(configSet, 'rtwsfcn.tlc', []);
For further information see the following link:
https://de.mathworks.com/help/rtw/examples/configuring-a-model-via-command-line.html?requestedDomain=de.mathworks.com