How to check if button is pressed in app designer?

조회 수: 14 (최근 30일)
William Pang
William Pang 2020년 7월 20일
댓글: 지아 백 2022년 12월 8일
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에서 Debugging and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by