MATLAB: Changing Value with Slider in App Designer
appdesignerchange value with sliderguislider
1
Best Answer
Ah, I misread your first post. But your second post clarifies everything. You have two problems:
On your line 103, your callback function to the slider value change is named GenerateButtonPushed. But in line 60, you call it as RPMSliderValueChanging - and this function does not exist, so you will not get any new n values read.
In addition, in your actual GenerateButtonPushed function, line 24, you set n=140 every time you push the generate button, so even if the slider read a new n, when you push the button you set n=140 again. Define n outside of your function - for example, on line 105, where you define all the GUI options is a good place to "initialize values".
This also means my first suggestion can be deleted - I have done this, and introduced the two other things, it seems to work for me although your axes are a little restrictive :)
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
GenerateButton matlab.ui.control.Button
RPMSliderLabel matlab.ui.control.Label
RPMSlider matlab.ui.control.Slider
end
methods (Access = private)
% Callback function: GenerateButton, RPMSlider
function GenerateButtonPushed(app, event)
global a
global V_f
global L
global S
global n
global D
a = 10;
V_f = 15;
L = 50;
S =120;
%n =140; If you have the n here, it is hardset to 140 every time you push the button
Hi, Erkin in App Designer instead of using the keyword global, you can declare the variables as Public Property, which can be used inside and out of the app. The attached zip file contains the app for your reference, where I have modified your functions.
Best Answer