How to prompt an error message box if no image is selected? (App Design)

3 ビュー (過去 30 日間)
Cyrick Elegado
Cyrick Elegado 2020 年 3 月 27 日
回答済み: Divya Yerraguntla 2020 年 3 月 30 日
I have an image processing project that I am currently working on. I would like to display a message box prompting an "error" if the user fails to select an image. As in:
The user selects load image, and if the user decides to exit out of the selection, an error message is shown. Thanks.
  1 件のコメント
Tommy
Tommy 2020 年 3 月 28 日
file = 0;
while ~file
[file, path] = uigetfile;
if ~file
waitfor(msgbox('Pick a file.'))
end
end
disp([path file])
This will bring up a dialog box for selecting a file, and if the user clicks 'Cancel' it will display another box that says 'Pick a file.' Once they close that box, it will again prompt them to pick a file. Only after they pick a file will the code continue past the while loop. Is this similar to what you are looking for?

サインインしてコメントする。

回答 (1 件)

Divya Yerraguntla
Divya Yerraguntla 2020 年 3 月 30 日
Hi Cyrick,
You could use the below model code to achieve your purpose:
[file,path] = uigetfile; % Open file selection dialog box
if isequal(file,0)
f = errordlg('Must pick a file'); % If cancel button is pressed Error pops up
end
Have a look at uigetfile and errordlg for more information about these functions.
Hope it helps!

カテゴリ

Help Center および File ExchangeGet Started with Image Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by