Changing Value with Slider in App Designer
Mostrar comentarios más antiguos
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 comentario
Rena Berman
el 2 de Feb. de 2024
(Answers Dev) Restored edit
Respuesta aceptada
Más respuestas (2)
Inso
el 9 de Dic. de 2019
0 votos
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 comentarios
Erkin Karatas
el 9 de Dic. de 2019
Erkin Karatas
el 9 de Dic. de 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
el 9 de Dic. de 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 comentario
Erkin Karatas
el 9 de Dic. de 2019
Categorías
Más información sobre Develop Apps Using App Designer en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!