フィルターのクリア

MATLAB GUI: I want to display an error message if user selects the wrong file type

3 ビュー (過去 30 日間)
MATLAB GUI HELP:
I have an option for users to open wav files (using uigetfile). However, this doesn't stop them opening all file types and when they do this it breaks my GUI.
How can I get an error message to occur when they don't open a wav file?
Many thanks. I really appreciate your help.
Best regards

採用された回答

Image Analyst
Image Analyst 2013 年 11 月 23 日
Try this fairly robust code:
numberOfTries = 0;
while numberOfTries < 20 % Failsafe
% Get the name of the file that the user wants to use.
startingFolder = pwd; % Whatever you want.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
break;
end
fullFileName = fullfile(folder, baseFileName)
[folder, baseFileName, extension] = fileparts(fullFileName)
if strcmpi(extension, '.wav')
break; % out of while loop
else
message = sprintf('Error: you must pick a wav file, not a "%s" file.', extension);
uiwait(warndlg(message));
end
end
  2 件のコメント
Paul
Paul 2013 年 11 月 24 日
Thanks, this is great
Image Analyst
Image Analyst 2013 年 11 月 24 日
You could also try to force them to pick a wave file by only showing them:
defaultFileName = fullfile(startingFolder, '*.wav');

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWavelet Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by