How to check if button is pressed in app designer?

92 次查看(过去 30 天)
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 个评论
Mohammad Sami
Mohammad Sami 2020-7-21
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.
지아 백
지아 백 2022-12-8
Hello
I've tried to solve this problem too, but it doesn't work.
Did you solve it?

请先登录,再进行评论。

回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by