How to make slider output a whole number? (Appdesigner)

조회 수: 11 (최근 30일)
Logan Das
Logan Das 2022년 5월 6일
편집: Logan Das 2022년 5월 6일
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
Sylvain
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
Logan Das
Logan Das 2022년 5월 6일
편집: Logan Das 2022년 5월 6일
Perfect! I can't mark your commect as answer (since its a comment)
Hope you don't mind if I just post it and mark it as solved

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

채택된 답변

Logan Das
Logan Das 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 CenterFile Exchange에서 Desktop에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by