MATLAB: Toggle manual switch through m-file script

manual switchsim

I want to toggle the manual switch block in Simulink using an m-file script.
….my model file is called "ecg_filter" and the manual switch is called "sw1", so I wrote in the m-file: set_param('ecg_filter/sw1','varsize','off') but the switch did not change positions, what am I doing wrong?

Best Answer

The parameter is called 'sw', not 'varsize'. You need to use:
>> set_param('ecg_filter/sw1', 'sw', '0')
>> set_param('ecg_filter/sw1', 'sw', '1')