Simulink dashboard switch to control masked parameter

4 visualizzazioni (ultimi 30 giorni)
I wanted to have a slider switch control such that On position would make it 1 Ohm and off position would make it 5 ohms.
The slider doesn't recognize the resistor as having any controllable parameters. If I go to variables tab and select override for the temperature, the switch would be able to control that alone.

Risposte (1)

Ninad
Ninad il 3 Nov 2023
Hi Matthew,
You may follow these steps to meet your requirement:
  1. Drag a "Slider Switch block" to a blank model.
  2. Connect it to a new "Constant block", so it takes input from the "Slider Switch block". At this point the value of the "Constant block" would be either 0 or 1 depending upon the slider stater ("off" or "on" respectively)
  3. Then, add a "Switch block" to the model, and connect the earlier created "Constant Block" to the second port of the switch block. Open the "Block Parameters" and change the "Criteria for passing the first input" parameter to "u2~=0".
  4. Connect the first input port of the "Switch Block" to constant value 1 and the third port to constant value 5.
  5. Connect the output of the "Switch Block" to the "To Workspace" block. Double click on the "To Workspace Block". Change the Variable name to "res".Now, you should be able to write the output of the "Switch Block" into a workspace variable.
  6. Now add a new "Resistor Block" to your model. Double click on the block. Set the value of the "Parameter">"Resistance" to "out.res.signals.values(1,1)", and "Save Format" to "Structure".This will read the resistance value from the workspace.
This is what the model will look like:
I have also attached the script for you reference. To test the result. You can try to change the slider states, run the model and check the value of the "out.res.signals.values" variable in the workspace.
Hope this helps.
Regards,
Ninad

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by