slider callback

10 visualizaciones (últimos 30 días)
mohamed khalaf
mohamed khalaf el 16 de Jul. de 2011
[EDIT: 201107`5 20:23 CDT - reformat - WDR]
hi all
i want to obtain the output of value a from callback function of slider
i used
h=uicontrol('Style', 'slider',...
'Min',0,'Max',1,'Value',0.01,...
'Position', [400 20 120 20],...
'Callback',{@su});
function a= su(h,event) %#ok<INUSL>
val =get(h,'Value');
a=val
end
i want the value after changing the slider position by mouse and i used:
d=su(h,'Value')
but it return the initial value of slider
thanks

Respuestas (2)

Fangjun Jiang
Fangjun Jiang el 16 de Jul. de 2011
No, I tried your code and it worked fine. Maybe:
1. You don't need the "end" statement
2. You need to save the function su() in a separate .m file as su.m
3. Or, add a line at the begining "function mygui" and save it as mygui.m and then run it.
  6 comentarios
mohamed khalaf
mohamed khalaf el 17 de Jul. de 2011
okay no way to call the value of a in exx()?
Fangjun Jiang
Fangjun Jiang el 17 de Jul. de 2011
You can call it but it's pointless, right? You just set its value to be 0.01 and then call it right away to get the value. Function exx() executes only once. Once the Slider is created, the code inside exx() is not longer executed.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 16 de Jul. de 2011
Seems a bit pointless.
h=uicontrol('Style', 'slider',...
'Min',0,'Max',1,'Value',0.01,...
'Position', [400 20 120 20]);
su = @() get(h,'Value');
Then, whenever you want the value, call su() -- having made sure that su is in scope for the place it is called.
  3 comentarios
Walter Roberson
Walter Roberson el 17 de Jul. de 2011
The code I gave doesn't store anything. Calling su() will always give the current value of the slider. If you are not seeing the current value of the slider in your code, perhaps your code is not waiting for the slider change before it extracts the slider value.
mohamed khalaf
mohamed khalaf el 17 de Jul. de 2011
okay i run your code
but the same problem appear again using su()the initial value is appear
thanks

Iniciar sesión para comentar.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by