Passing slider value to the simulink model

Hello, I am trying to pass / control values from a slider using GUIDE to simulink model as one of the inputs. However not able to do so as not getting the work around for using set_param. Could someone help me with the steps. I am new to the programming world so your guidance and help will be really appreciated.

Respuestas (2)

Sebastian Castro
Sebastian Castro el 13 de Abr. de 2015
If your block is currently selected, you can use gcb to get the block's name.
>> get_param(gcb,'gain')
>> set_param(gcb,'gain','5')
If already know the name of the block, just replace gcb with the actual name -- for example, 'myModel/Slider Gain'.
- Sebastian
Aasif Shaikh
Aasif Shaikh el 13 de Abr. de 2015

0 votos

Hi Sebastian, thanks for your reply. So what is gain here ? is it the signal name in simulink model. And where does the value '5' come from ? I want to send the values from the slider to the model.
Thanks

4 comentarios

Sebastian Castro
Sebastian Castro el 13 de Abr. de 2015
First of all: Please respond to answers with comments. Otherwise, the conversation can get out of order depending on the number of votes, etc.
Sorry, I somehow read that you wanted to interact between GUIDE and a Slider Gain block. What exactly are you looking to do -- change a slider value in GUIDE and then pass that constant value to a block in Simulink? If so, which block(s)?
Aasif Shaikh
Aasif Shaikh el 14 de Abr. de 2015
I am trying to create a GUI (using GUIDE) which has a slider. Now I want to use this slider as an input to one of the signals / variables in simulink model. So whatever value I change in the GUI the same should be passed onto the simulink variable.
Thanks
Aasif Shaikh
Aasif Shaikh el 14 de Abr. de 2015
Just to add, need to pass that value to a constant block in the simulink model.
OK, so it should be (for example):
blockName = 'myModel/Constant';
x = 14;
set_param(blockName,'Value',num2str(x));
- Sebastian

Iniciar sesión para comentar.

Categorías

Preguntada:

el 13 de Abr. de 2015

Comentada:

el 14 de Abr. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by