How to make slider output a whole number? (Appdesigner)
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.

Heres just the code within the slider callback

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 commentaires
Sylvain
le 6 Mai 2022
% 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
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Desktop dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!