필터 지우기
필터 지우기

How to display an error message in GUI?

조회 수: 13 (최근 30일)
slumberk
slumberk 2011년 2월 17일
I have a figure of table. The user will insert a data into the table. If the user suddenly inserts the wrong data, the table will be 'NaN'. My question is how I want to make the table does not display 'NaN' on the table but I want an error message appear. I have this coding:
function Mytable1_CreateFcn(hObject, eventdata, handles)
if isnan(Mytable1)
set(hObject, 'Data', 0);
errordlg('Input must be a number','Error');
end
handles.Mytable2 = hObject;
guidata(hObject,handles);
But there is an error with this code. Is this coding are correct to answer my question?

채택된 답변

Walter Roberson
Walter Roberson 2011년 2월 17일
You wouldn't put the test in the create function, you would put the test in the edit function.
You may also want to uiwait() around the errordlg() so that you force the user to acknowledge the error. Your present code pops up the error but the user can hide it and continue on their way.
  댓글 수: 3
Walter Roberson
Walter Roberson 2011년 2월 17일
ed = errordlg('Input must be a number','Error');
set(ed, 'WindowStyle', 'modal');
uiwait(ed);
It might be possible to make it impossible for the user to hide it, but it probably isn't worth the bother: with the above code, the user will not be able to proceed with anything else.
Paulo Silva
Paulo Silva 2011년 2월 17일
To show errors I often prefer to have them inside a text box, it's also good to show warnings and important info, also changing the text colors with the message type is great.

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

추가 답변 (2개)

slumberk
slumberk 2011년 2월 18일
@walter and paulo:
I did this coding on Mytable1_CellEditCallback. It still have error. Is this code true??
Mytable1=get(hObject,'Data')
if isnan(Mytable1)
set(hObject, 'Data', 0);
h=errordlg('Oh noes!','Error');
set(h, 'WindowStyle', 'modal');
uiwait(h);
return
end
handles.Mytable2 = hObject;
guidata(hObject,handles);
This is the error:
Mytable1 =
[1] [] []
[] [] []
[] [] []
[] [] []
??? Undefined function or method 'isnan' for input arguments of type 'cell'.
Error in ==> fyp_editor>Mytable1_CellEditCallback at 795 if ~isnan(Mytable1)
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> fyp_editor at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)fyp_editor('Mytable1_CellEditCallback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uitable CellEditCallback
  댓글 수: 4
Matt Fig
Matt Fig 2011년 2월 18일
No, it is not a matrix. If it was a matrix, the error message wouldn't say,
"??? Undefined function or method 'isnan' for input arguments of type 'cell'."
Paulo Silva
Paulo Silva 2011년 2월 18일
all(cellfun(@isempty,Mytable1))

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


slumberk
slumberk 2011년 2월 18일
@matt: i dont realy get what you are asking. So i just paste the code that from pushbuttons callback:
data1 = get(handles.Mytable1,'Data');
data2 = get(handles.Mytable2,'Data');
cost = cell2mat(get(handles.Mytable1,'Data'));
limit = cell2mat(get(handles.Mytable2,'Data'));
Is this answer you?
  댓글 수: 2
Matt Fig
Matt Fig 2011년 2월 18일
Where is this code in relation to the code you posted previously? If you pay attention to the error messages, it clearly says you are trying to use ISNAN with a cell array.
slumberk
slumberk 2011년 2월 18일
@matt: Ok.. Let me tell you true process. I have a figure of table and a pushbuttons. The user will insert the data into the table but assume the user accidentally insert a wrong data. For example:
ALPHA BETA GAMMA
C1
C2
C3
If the user only want to use C1 and C2 but the user accidentally insert a data on C3 then he delete the data from C3 at column ALPHA and the column ALPHA at row C3 will become NAN. So how i want an error message says 'Please complete C3' and I dont want it become 'NAN' but i want to leave it blank. How can i make it?

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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by