GUI report error if something is wrong

1 回表示 (過去 30 日間)
Xin
Xin 2017 年 9 月 27 日
コメント済み: OCDER 2017 年 9 月 27 日
I have a GUI that has a static text box which I use to update for the status of the code. The GUI needs to load data from an excel file (xlsread), and sometimes the load fails due to mistakes in the data file. I want to have a string saying "Error loading data!" to appear if the xlsread function fails. Is there a good way to do it. Thanks

採用された回答

OCDER
OCDER 2017 年 9 月 27 日
You could use try/catch statements where you use the xlsread function. Edit the code in your callback function like this:
try
NumData = xlsread(FileName); %wrap your xlsread with try/catch statement
catch
set(handles.text1, 'String', 'Error loading data!'); %update your status text
drawnow; %redraw GUI to ensure the new string shows
return %end the callback function prematurely due to error
end
  2 件のコメント
Xin
Xin 2017 年 9 月 27 日
Sounds great. It worked. Thanks!
OCDER
OCDER 2017 年 9 月 27 日
You're welcome!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by