MATLAB: How to programmatically comment/uncomment a Simulink block

simulink

Simulink blocks can be commented/uncommented using Ctrl+Shift+X.
Is there a way to do this programmatically in a Matlab script?

Best Answer

Yes, you can do
set_param(blockName,'Commented','on')
set_param(blockName,'Commented','off')
... or if the block has 1 input and 1 output port, you can also comment through
set_param(blockName,'Commented','through')
Here, blockName is the name of the block, which you can obtain by selecting the block and typing gcs.
- Sebastian