Update slider value while in a for loop.

조회 수: 4 (최근 30일)
Sampath reddy
Sampath reddy 2012년 5월 6일
I am running a program in GUI.It contains a for loop. One of the parameters in the program is controlled by slider. While inside the for loop, i want to change the slider value so that the program continues to run with the new slider value. How to do this?

답변 (2개)

Walter Roberson
Walter Roberson 2012년 5월 6일
set(SliderHandle, 'Value', NewValue)
However, this will not be enough if the program fetches the slider value and stores it and then uses the stored value instead of re-fetching the slider value.

Image Analyst
Image Analyst 2012년 5월 6일
If you want the user to change it interactively while the loop is running, you can get the value inside your loop.
sliderValue = get(handles.slider, 'Value');
Again, that is inside your loop.
When the user moves the slider, the slider callback gets called. In that callback, be sure and call "drawnow" or else it might be so involved in your loop that it won't have time to update your slider caption right away. I'm assuming you have a static text above your slider that gives the value, something like:
sliderValue = get(handles.slider, 'Value');
sliderCaption = sprintf('The slider value = %f', sliderValue);
set(handles.slidertext, 'String', sliderCaption);
drawnow;
  댓글 수: 2
Sampath reddy
Sampath reddy 2012년 5월 7일
I'm getting an error saying Invalid or deleted object(handles.slider) for the line sliderValue = get(handles.slider, 'Value');
I'm unable to figure out the problem
Image Analyst
Image Analyst 2012년 5월 7일
Are you using GUIDE? What is the name of the handle to your slider? If you're using GUIDE, this is the 'tag' property.

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by