MATLAB Answers

How to check if button is pressed in app designer?

100 views (last 30 days)
William Pang
William Pang on 20 Jul 2020
Answered: Cris LaPierre on 21 Jul 2020
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

  1 Comment

Mohammad Sami
Mohammad Sami on 21 Jul 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.

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 21 Jul 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".

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!