How to change values of variable in both increasing and decreasing manner in GUI ?

조회 수: 3 (최근 30일)
Hello all, As we use slider for changing values of variable continuously in GUI , but slider changes values in one direction only (say 0 to 10), Is it possible to change values in other direction (-10 to 0) also ? because I have an object at origin and I want to move that in +x and -x direction with using one slider . Is that any other way to do that ? Please give me some suggestions . Thank you

답변 (1개)

Joseph Cheng
Joseph Cheng 2016년 1월 14일
is this not just setting the max and min properties of the slider to a min value of -10 and max value of 10? example:
function slidetest2()
hfig = figure(1);
hslide = uicontrol('style','slider','units','normalized','position',[.2 .6 .6 .05],'callback',@dispslideval)
set(hslide,'max',10)
set(hslide,'min',-10)
function dispslideval(hobj,event)
disp(get(hobj,'value'))
  댓글 수: 3
Joseph Cheng
Joseph Cheng 2016년 1월 14일
well not seeing how you implement it how about just varying the interpretation of the slider range. so for example the slider is only from 0 to 10 then to get it to go from -10 to 10 is it now (2*sliderval -10)? read in the value and then offset it.
Nicolás Casaballe
Nicolás Casaballe 2016년 3월 31일
Try the above approach by including the pair 'Min',-10 alongside the other parameters within the call to uicontrol that creates the slider. Should read similar to
hslide = uicontrol('style','slider',...
'units','normalized',...
'position',[.2 .6 .6 .05],...
'Min',-10,...
'callback',@dispslideval)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by