use the same result in different callback in matlab app desinger

1 view (last 30 days)
hello,
I am problem that i solved using the app desiner in two step calculation but the second calculation depend on the first one each of them in edit field numeric
so how can I callback the first numeric field value to the calculation of second nuemric field
for example
a=5
b=6
c=5
x1=a*b; % this is in the first nuemricafield.value
then in second numerical field
x2=x1^c in second nuemric field
so how can i express the x1 value of first numerica field in app desinger
Thank u

Accepted Answer

Voss
Voss on 24 Mar 2022
Let's say the first NumericEditField is called EditField1 and the second one is called EditField2, and their ValueChangedFcns are called ValueChangedFcn_EditField1 and ValueChangedFcn_EditField2, respectively.
In general, you can get or set any NumericEditField's value wherever you need to by referring to app.EditField1.Value or app.EditField2.Value (or whatever they are called in your app).
So, in this situation, in the second NumericEditField's ValueChangedFcn, you can get the value of the first NumericEditField:
function ValueChangedFcn_EditField2(app,evt)
x1 = app.EditField1.Value;
% now do whatever you need to do with x1
end
And you also might update EditField2's Value whenever EditField1's Value changes:
function ValueChangedFcn_EditField1(app,evt)
x1 = app.EditField1.Value;
c = 5;
x2 = x1^c;
% set EditField2's Value to x2:
app.EditField2.Value = x2;
end
  6 Comments
Voss
Voss on 24 Mar 2022
Take a look at the attached .mlapp file. In that app, when EditField1 changes, EditField2's Value is set to the fifth power of EditField1's Value; when EditField2's Value changes, nothing else changes.
Try to compare the relevant parts of your app wth this app and see if there is anything different between the two that might explain why your app doesn't seem to update when it should.
If that doesn't work, can you attach your .mlapp file (and I'll take a look at it)?

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!