increasing slider value of a GUI

1 visualizzazione (ultimi 30 giorni)
Yassine Zaafouri
Yassine Zaafouri il 15 Feb 2017
Modificato: Yassine Zaafouri il 16 Feb 2017
i want to increment the value of my slider with a 10 unit step when the user clicks on an arrow at the ends of the scrollbar: [10:10:300]
How can I do this with the Property Inspector ?
thank you

Risposta accettata

Jan
Jan il 15 Feb 2017
Modificato: Jan il 15 Feb 2017
figure;
uicontrol('Style', 'Slider', 'Position', [10, 10, 200,20], ...
'SliderStep', [1/29, 0.1], ...
'Min', 10, 'Max', 300, 'Value', 10, ...
'Callback', 'disp(get(gcbo, ''Value''))')
The range goes from 10 to 300, which is a distance of 290. To get a stepsize of 10, the SliderStep must be 10/290, or 1/29. You should expect rounding errors, so fix the value in the callback:
uicontrol('Style', 'Slider', 'Position', [10, 10, 200,20], ...
'SliderStep', [1/29, 0.1], ...
'Min', 10, 'Max', 300, 'Value', 10, ...
'Callback', mySliderCB);
function mySliderCB(SliderH, EventData)
Value = round(get(SliderH, 'Value'));
set(SliderH, 'Value', Value);
...

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by