Problem with sliders and plot (App Designer)
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Conrado Santurino
le 25 Fév 2020
Réponse apportée : Cameron B
le 26 Fév 2020
Hello, I'm using Matlab App Designer and I have a problem. Considering this design:
If a and b are the values on which the sliders alpha and beta are positioned, respectively, I wanted to plot this function:
f(x) = ax + b.
I have been trying a lot changing variables on this code, but with no success. Sometimes beta value doesn't apear and it plots only y = ax... I don't know. This is the code where I'm stuck.
% Callbacks that handle component events
methods (Access = private)
% Value changing function: alfaSlider
function alfaSliderValueChanging(app, event)
alfa = event.Value;
x = 0:0.01:100;
y = alfa.*x + app.betaSlider.Value;
plot(app.UIAxes,x,y)
end
% Value changing function: betaSlider
function betaSliderValueChanging(app, event)
beta = event.Value;
x = 0:0.01:100;
y = beta + 0.*x + app.alfaSlider.Value;
plot(app.UIAxes,x,y)
end
.
.
.
How could I plot f(x) using a and b as the inputs of the slide bars?
Thanks in advance
0 commentaires
Réponse acceptée
Cameron B
le 26 Fév 2020
I think this is what you mean but let me know if I’m wrong.
% Callbacks that handle component events
methods (Access = private)
% Value changing function: alfaSlider
function alfaSliderValueChanging(app, event)
x = 0:0.01:100;
y = app.alfaSlider.Value*x + app.betaSlider.Value;
plot(app.UIAxes,x,y)
end
% Value changing function: betaSlider
function betaSliderValueChanging(app, event)
x = 0:0.01:100;
y = app.betaSlider.Value + app.alfaSlider.Value*x;
plot(app.UIAxes,x,y)
end
You could make this shorter by just having one callback written for both of them (they do the same thing), but that’s not super important for something with a few lines of code.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Develop Apps Using App Designer 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!