Problem with sliders and plot (App Designer)

5 次查看(过去 30 天)
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

采纳的回答

Cameron B
Cameron B 2020-2-26
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 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by