App Designer MATLAB: if-else condition not working

2 Ansichten (letzte 30 Tage)
Makram
Makram am 15 Okt. 2022
Verschoben: Image Analyst am 16 Okt. 2022
I am creating a GUI in App Designer (version: MATLAB R2022b).
I have a first function configured which allows users to Load an image in the GUI (important part of the code: I transform the value of another button on the app, the StatebuttonButton, to 1 at the end of the function exection):
function LoadimageButtonPushed(app, event)
[filename,filepath]=uigetfile({'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files'},'Select an image');
fullname=[filepath, filename];
ImageFile=imread(fullname);
imagesc(app.UIAxes_3, ImageFile);
app.StatebuttonButton.Value = 1;
end
Then a second function that should allow users to crop the image loaded above. However, I want to make sure that an image was loaded by the user in the first place (before pushing the crop button), so I have configured the if-else statement below to do so. Based on the "Value" of app.StatebuttonButton, it should know whether an image was loaded in the first place:
function CropButtonPushed(app, event)
if not(app.StatebuttonButton.Value == 1)
f=errordlg('Please load an image first','User Action Error');
else
;
end
% rest of function
% rest of function
end
The problem is that the if-else statement is not working, and I am not even receiving any error from MATLAB explaining why.
Can someboy help?

Akzeptierte Antwort

Hiro Yoshino
Hiro Yoshino am 16 Okt. 2022
Verschoben: Image Analyst am 16 Okt. 2022
I found a solution for this.
errordlg is not suitable for App Designer; you should use uialert instead. There is a small note at the bottom of the errordlg document and it says use "uialert" in the case of app building.
Hope this helps.

Weitere Antworten (1)

Hiro Yoshino
Hiro Yoshino am 15 Okt. 2022
Bearbeitet: Hiro Yoshino am 15 Okt. 2022
What is the default value for app.StatebuttonButton.Value? Have you checked it in the first place?
If it is "1", it always skip the if condition even when you haven't uploaded any images.
  4 Kommentare
Makram
Makram am 15 Okt. 2022
Thanks for the help. I ended up finding a better solution, I made the "cropbutton" invisible when the app is started, and then only when an image is loaded I make it visible.
Mak
Mak am 16 Okt. 2022
Indeed! Thanks for your help.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Debugging and Analysis finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by