How to set Simulink Manual Switch position programmatically

You can set the position of a Simulink Manual Switch programmatically using the set_param function in MATLAB:

% Set the position of a Manual Switch block to the upper position
set_param('MySimulinkModel/Manual Switch', 'sw', '1');

% Set the position of a Manual Switch block to the lower position
set_param('MySimulinkModel/Manual Switch', 'sw', '0');