Problem with sliders and plot (App Designer)

5 visualizaciones (últimos 30 días)
Conrado Santurino
Conrado Santurino el 25 de Feb. de 2020
Respondida: Cameron B el 26 de Feb. de 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

Respuesta aceptada

Cameron B
Cameron B el 26 de Feb. de 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.

Más respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by