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');

 Réponse acceptée

Voss
Voss le 23 Oct 2023

0 votes

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 commentaires

Agnes S
Agnes S le 24 Oct 2023
it worked, thank you!
Voss
Voss le 24 Oct 2023
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by