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

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