How to check if button is pressed in app designer?

9 vues (au cours des 30 derniers jours)
William Pang
William Pang le 20 Juil 2020
Commenté : 지아 백 le 8 Déc 2022
Hi! So I've designed an app for doing some image processing, as shown below:
So I want users to be able to load images by pressing either "Single Image" or "Multiple Images". Once the images are loaded, users can then input values into "Filter Size", "threshold", and "Cut Cells Size" and then press the "Compute button".
However, I want my app to run a different code depending on whether the user pressed "Single Image" or "Multiple Image" upon pressing "Compute". I'm having a bit of trouble making this work, and I'm wondering why the below code doesn't work:
function ComputeButtonPushed(app,event)
if app.SingleImageButtonPushed.Value == 1;
%Run this code
elseif app.MultipleImagesButtonPushed.Value ==1;
%Run this code
end
  2 commentaires
Mohammad Sami
Mohammad Sami le 21 Juil 2020
Are the buttons you used of the type "toggle buttons" ?
Also I assume the user should not be allowed to press both buttons. Therefore you might want to put the two toggle buttons inside the button group.
지아 백
지아 백 le 8 Déc 2022
Hello
I've tried to solve this problem too, but it doesn't work.
Did you solve it?

Connectez-vous pour commenter.

Réponses (1)

Cris LaPierre
Cris LaPierre le 21 Juil 2020
A simple solution would be to create a property in the app, say something like "app.isSingle". If the "Single Image" button is pressed, its callback code sets the value of this property to "true". If "Multiple Images" is pressed, its callback sets the value to "false". Use this value in the logic of your if statement in the callback function for "Compute".

Catégories

En savoir plus sur Debugging and Analysis dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by