increasing slider value of a GUI

1 Ansicht (letzte 30 Tage)
Yassine Zaafouri
Yassine Zaafouri am 15 Feb. 2017
Bearbeitet: Yassine Zaafouri am 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

Akzeptierte Antwort

Jan
Jan am 15 Feb. 2017
Bearbeitet: Jan am 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);
...
  1 Kommentar
Yassine Zaafouri
Yassine Zaafouri am 16 Feb. 2017
Bearbeitet: Yassine Zaafouri am 16 Feb. 2017
Thank you verry much !

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by