Problem with sliders and plot (App Designer)

조회 수: 6 (최근 30일)
Conrado Santurino
Conrado Santurino 2020년 2월 25일
답변: Cameron B 2020년 2월 26일
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