MATLAB Answers

GUI report error if something is wrong

조회 수: 2(최근 30일)
Xin 27 Sep 2017
댓글: OCDER 27 Sep 2017
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 27 Sep 2017
You could use try/catch statements where you use the xlsread function. Edit the code in your callback function like this:
NumData = xlsread(FileName); %wrap your xlsread with try/catch statement
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
  댓글 수: 2
OCDER 27 Sep 2017
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변(0개)


Community Treasure Hunt

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

Start Hunting!

Translated by