How to detect a value changing in matlab app - numeric edit field

조회 수: 27 (최근 30일)
Tom
Tom 2022년 8월 31일
답변: Ankit 2022년 8월 31일
Dear Community,
I am currently working on a MatLab app and i am changing the value of a numeric edit field by using a matlab function. Everytime the value changes, i want to execute an operation.
I tried to do it with a ValueChanged Callback, but i figured that it doesn´t work if you dont manually change the value of the edit field. Does anyone know how to detect a changed value if it isn´t changed manually but by another function?
I hope my Problem is clear. Thanks for helping in advance!

채택된 답변

Ankit
Ankit 2022년 8월 31일
@Tom: I have created one simple example for you.
In this example when the EditField values are changed I am doing different operations like addition, multiplication and division. EditField values i am changing from a function named "startSimulation(app)"
function startSimulation(app)
i = 0;
while i<=10 && app.stop_sim == false
app.display.Value = num2str(i);
pause(0);
displayValueChanged(app)
i = i + 2;
end
end
As I am not aware about your operations, you can imagine similar to yours.
I created a displayValueChanged function and then added to the Callbacks of EditField and Output.
% Value changed function: Output, display
function displayValueChanged(app, event)
value = app.display.Value;
switch value
case '2'
app.Operator.Text = '+';
app.Output.Value = app.A.Value + app.B.Value;
case '4'
app.Operator.Text = '*';
app.Output.Value = app.A.Value*app.B.Value;
case '10'
app.Operator.Text = '/';
app.Output.Value = app.A.Value/app.B.Value;
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by