I'm working in MATLAB and want to obtain the value of a slider and use it as an input for calculations in another function. How can I retrieve the slider's value and pass it to another function? I attempted to use get(h,'value'), but encountered an error. How should I go about this?
Error encountered while using get:
Error using matlab.graphics.Graphics/get
Property value not found in class matlab.graphics.GraphicsPlaceholder, or is not present in all
elements of the array of class matlab.graphics.GraphicsPlaceholder.
Here's what I tried doing:
hslide(i) = uicontrol('style','slider','units','normalized');
value = get(hslide,'value');

 채택된 답변

Voss
Voss 2023년 10월 23일

0 개 추천

You are storing the slider object in an array. hslide is the array, and hslide(i) is the slider. When you try to get the value, you are getting the Value of each element of the array, but not all elements of the array are sliders (in particular some are GraphicsPlaceholders, maybe because you haven't created those sliders yet), which causes the error.
If you intend to store your slider in an array and just get the value of the ith slider in that array, then
hslide(i) = uicontrol('style','slider','units','normalized');
value = get(hslide(i),'value');
Or if you do not intend to store slider in an array, then:
hslide = uicontrol('style','slider','units','normalized');
value = get(hslide,'value');

댓글 수: 2

Agnes S
Agnes S 2023년 10월 24일
it worked, thank you!
Voss
Voss 2023년 10월 24일
You're welcome!

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

추가 답변 (0개)

카테고리

제품

릴리스

R2023a

질문:

2023년 10월 23일

댓글:

2023년 10월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by