Toggle manual switch through m-file script

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?

 Accepted 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')

4 Comments

I tried this code aswell, but the problem I'm facing is the following: When I try to control the manual switch in my simulink model, I use the code:
set_param('path-to-switch-in-model', 'sw', '0')
As I always try commands in the Matlab console first, the following error showed up:
annotation does not have a parameter named 'sw'
The next step I took was to add the annotation in the manual switch (right click on the switch --> properties -->block annotations). 'sw' was not in the list, so I typed it in there myself (sw = %<sw>) and I could see the number shifting between 0 and 1 when I was switching. I tried the same line of code again, but it still didn't work...
I temporary changed the manual switch for a normal switch, controlled by a constant block to get rid of the problem. But this is just temporary because I'd love to make a GUI and Simulink model that are synced to each other and the user can choose where he wants to interact with: the GUI or the Simulink model...
I hope at least someone knows how to solve this problem?! thanks in advance!
The accepted answer works. >> set_param('ecg_filter/sw1', 'sw', '0') >> set_param('ecg_filter/sw1', 'sw', '1')
But since this was reported in 2012,,,,, WHY IS THERE NO UPDATE TO THE DOCUMENTATION, OR WHY IS 'SW' HIDDEN. I CAN FIND NO REFERENCE TO IT ANYWHERE ! MATLAB, I EXPECT THAT THIS VERY BASIC LEVEL OF DOCUMENTATION TO BE INCLUDED FOR THE MANUAL SWITCH BLOCK. I WILL SUBMIT A SUPPROT CASE, BUT I FIND IT HARD TO BELIEVE THAT SOMETHING SO BASIC IS HIDDEN.
New to Simulink - and getting frustrated,,, Dr Mike Brewin.
Hi people. How did you find that the parameter is called 'sw'? I am trying to use same kind of parameter in manual variant sink block but unable to find a parameter for the same. Thank you. :)
How did you change the position of the toggle swicth using the value of output in a simulink block?

Sign in to comment.

More Answers (0)

Categories

Find more on Modeling in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!