How to extract a slider value?

7 次查看(过去 30 天)
Darío Imbernón Clavero
编辑: VBBV 2024-5-18
%Slider
fig = uifigure('Position',[100 100 350 275]);
pnl1 = uipanel(fig);
sld1 = uislider(pnl1,'Position',[100 40 120 3],... 'ValueChangingFcn',@(sld,event1) slider1(event1));
sld1.Limits = [-100 100];
sld2 = uislider(pnl1,'Position',[100 100 120 3],... 'ValueChangingFcn',@(sld,event2) slider2(event2));
sld2.Limits = [-100 100];
sld3 = uislider(pnl1,'Position',[100 180 120 3],... 'ValueChangingFcn',@(sld,event3) slider3(event3));
sld3.Limits = [-100 100];
I'm trying to make a program to extract the power of my engine from the sliders I declared(each one corresponds to one engine). So I need to extract the value of each slider when i dragg it as an integer variable, if anyone can help it will be great.
Thanks!

回答(2 个)

Adam Danz
Adam Danz 2021-4-20
编辑:Adam Danz 2021-4-20
See the value property in the slider documentation.
  3 个评论
Darío Imbernón Clavero
I put this for to read the values of the slider as you said, but it sends me this error. I dont find any information about it.
Adam Danz
Adam Danz 2021-4-21
编辑:Adam Danz 2021-4-23
The first line of the error message tells you what the problem is.
slider3 is not defined.
You probably mean app.slider3 assuming that's the handle to your slider.

请先登录,再进行评论。


VBBV
VBBV 2024-5-18
编辑:VBBV 2024-5-18
@Darío Imbernón Clavero, You can call the ValueChangedFcn property for the uislider function, and define functions for ValueChangedFcn names given inside the uislider function. This will make the slider functions output the slider value accordingly and get rid of the for loop. The sld and event are common input arguments for the slider functions to record the events by user clicks on slider component.
clc
clear all
fig = uifigure('Position',[100 100 350 275])
pnl1 = uipanel(fig)
sld1 = uislider(pnl1,'Position',[100 40 120 3],'ValueChangedFcn',@(sld,event) slider1(event))
sld1.Limits = [-100 100]
sld2 = uislider(pnl1,'Position',[100 100 120 3],'ValueChangedFcn',@(sld,event) slider2(event))
sld2.Limits = [-100 100]
sld3 = uislider(pnl1,'Position',[100 180 120 3],'ValueChangedFcn',@(sld,event) slider3(event))
sld3.Limits = [-100 100]
% call the ValueChangedFcn
a = sld1.ValueChangedFcn;
b = sld2.ValueChangedFcn;
c = sld3.ValueChangedFcn;
% define the functions for ValueChangedFcn names given inside the uislider
function a = slider1(event)
a = event.Value
end
function b = slider2(event)
b = event.Value
end
function c = slider3(event)
c = event.Value
end

类别

Help CenterFile Exchange 中查找有关 Language Fundamentals 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by