How to make slider output a whole number? (Appdesigner)
25 次查看(过去 30 天)
显示 更早的评论
I've connected a slider with an edit field (moving the slider changes value in edit field and vise versa)
Problem is sometimes the slider will give a decimal wheres I need it to always round to nearest whole number.![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/989020/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/989020/image.png)
Heres just the code within the slider callback
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/989025/image.png)
Image for better visualitaion plus code on bottom to copy
% Callbacks that handle component events
methods (Access = private)
% Value changed function: RealisationsSlider
function RealisationsSliderValueChanged(app, event)
slider_value = app.RealisationsSlider.Value;
app.RealisationsEditField.Value = slider_value; % make slider and edit box linked
end
any suggestions?
Much appreicated!
2 个评论
Sylvain
2022-5-6
% Value changed function: RealisationsSlider
function RealisationsSliderValueChanged(app, event)
slider_value = app.RealisationsSlider.Value;
app.RealisationsEditField.Value = round(slider_value); % make slider and edit box linked
app.RealisationsSlider.Value = round(slider_value); % update the slider itself
end
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!