MATLAB: Problem with sliders and plot (App Designer)

app designerMATLAB and Simulink Student Suite

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

Best Answer

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.