Changing Value with Slider in App Designer
Show older comments
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;
D=50;
x = 1:50;
y = 1:50;
V_w = (V_f * pi * D * n)/(2*L*S);
for i = 1:length(y)
hor(i) = V_w * sqrt(2*y(i)/a);
i = i+1;
end
plot(y,hor, 'r')
hold on
for i=1:100;
k = y - i;
plot(k, hor, 'r')
hold on
m = -x - i;
plot(m, hor, 'b')
hold on
i= i +1;
end
end
Hi all, I have implemented this code into app designer, and I want to change the 'n' value with slider.
function RPMSliderValueChanging(app, event)
changingValue = event;
n = changingValue;
end
I have created a callback for adjusting the n value. I want to change the n value and then plot the updated figure. However, the plot does not change when I change the value with slider. Can someone please help me. Thanks
1 Comment
Rena Berman
on 2 Feb 2024
(Answers Dev) Restored edit
Accepted Answer
More Answers (2)
Inso
on 9 Dec 2019
0 votes
This is because 'n' is not a global variable in RPMSliderValueChanging function.
You can either claim n to be global in the callback function or create n as a property of you app to pass the data.
4 Comments
Erkin Karatas
on 9 Dec 2019
Erkin Karatas
on 9 Dec 2019
Sorry I mistype something. It should be:
function RPMSliderValueChanging(app, event)
global n
changingValue = event;
n = changingValue;
cla(gca)
GenerateButtonPushed(app, event)
end
Also assign all the global variables in the Startup function instead of in GenerateButtonPushed.
Jakob B. Nielsen
on 9 Dec 2019
Currently, all your slider event function does is read a new value of n. The figure will only change if you specifcy that it must, so include that in your slider value change event, and see if that works.
function RPMSliderValueChanging(app, event)
changingValue = event;
n = changingValue;
V_w = (V_f * pi * D * n)/(2*L*S);
for i = 1:length(y)
hor(i) = V_w * sqrt(2*y(i)/a);
i = i+1;
end
plot(y,hor, 'r')
hold on
for i=1:100;
k = y - i;
plot(k, hor, 'r')
hold on
m = -x - i;
plot(m, hor, 'b')
hold on
i= i +1;
end
end
1 Comment
Erkin Karatas
on 9 Dec 2019
Categories
Find more on Create Custom UI Components in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!