if pushutton1 is pressed, how to use the value associated with it for displaying result for pushbutton2 in GUI ?

1 visualizzazione (ultimi 30 giorni)
I am working on GUI. I have two pushbuttons, pushbutton1 and pushbutton2. Also I can give three input integer values. When pushbutton1 is pressed, it displays result (for instance, multiplication of three input values a*b*c). I want that if pushbutton1 is already pressed, and after pressing pushbutton2, it shoud hold the previous input value (only a) and I should be able to change other values b and c and thus display the result of a*b*c. I don't know how to hold value a and change other values b and c by pressing pushbutton2. Please help.

Risposta accettata

Voss
Voss il 18 Giu 2022
If you want to prevent the user from changing the value in the 'a' edit box, you can set the 'Enable' property of that edit box to 'off' or 'inactive'.
set(edit_a,'Enable','off') % disabled
% - or -
set(edit_a,'Enable','inactive') % disabled, but looks enabled
(Also, you may consider making pushbutton2 a togglebutton rather than a pushbutton, since you can use the Value property of a togglebutton to determine whether it is currently pressed or not. Using a checkbox may be an appropriate alternative as well.)

Più risposte (1)

Image Analyst
Image Analyst il 18 Giu 2022
In the callback for button 1, record its pushed status and original value of a. Untested code:
% Get value of a from the edit field and save it as field of app.
app.a = app.edta.Value;
% Log that pushbutton 1 was clicked.
app.button1Clicked = true;
Now in your code for button 2 you can retrieve the value of a if button 1 was clicked. You can also change b and c in that callback if you want
if app.a
% Button 1 has been clicked already. Use original value for a
a = app.a;
else
% Button 1 has not yet been clicked. Get value from edit field.
a = app.edta.Value;
end
% Get current value of b and c from the edit field.
b = app.edtb.Value;
c = app.edtc.Value;
% Change b and c if you want
b = 5;
app.edtb.Value = b;
c = 20;
app.edtc.Value = c;
% Put product into the result edit field
app.edtResult.Value = a*b*c;
Not sure if you can use value with numbers. You might have to use the String property and str2double and num2str if it doesn't work.

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by