GUI edit text and msgbox problem .. what do I miss
조회 수: 16 (최근 30일)
이전 댓글 표시
Hello,
yesterday I programed partial code that does check values in edit text field for NUMBER and then If that is a number pops out msgbox where that number is shown othervise it htere is STR it pops msg box ERROR.
Unfortunately! It worked well till now. I'm not aware of changing anything! And I cannot find problem.
function koefm_Callback(hObject, eventdata, handles)
input = get(handles.koefm,'String'); %get the input from the edit text field
input = str2num(input); %change from string to number
if isempty(input)
msgboxText{1} = 'BLAH BLAH';
msgbox(msgboxText,'BLAH', 'error');
set(handles.koefm,'String','2') % sets default value
else
input = num2str(input);
msgboxText{1} = 'blah blas';
msgboxText{2} = strcat('blah blah',{' '},input) ;
msgbox(msgboxText,'INFO');
end
It should be in conversion but I can't see the problem.. help please :P
BTW this is command line error msg input =
6
input =
6
??? Undefined function or method 'eq' for input arguments of type 'cell'.
Error in ==> textwrap at 99
Loc=find(Para==ReturnChar);
Error in ==> msgbox at 283
[WrapString,NewMsgTxtPos]=textwrap(MsgHandle,BodyTextString,75);
Error in ==> GUI>koefm_Callback at 95
msgbox(msgboxText,'INFO');
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> GUI at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)GUI('koefm_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
댓글 수: 0
채택된 답변
Matt Fig
2011년 6월 12일
This works:
input = get(handles.koefm,'String'); %get the input from the edit text field
% No need to convert to number...
if isempty(input)
msgboxText{1} = 'BLAH BLAH';
msgbox(msgboxText,'BLAH', 'error');
set(handles.koefm,'String','2') % sets default value
else
msgboxText{1} = 'blah blas';
msgboxText{2} = ['blah blah',' ',input]; % The error was here.
msgbox(msgboxText,'INFO');
end
The error was that you were using STRCAT to make a cell array with a sub-cell... Look at the results of what you did:
msgboxText{1} = 'blah blas';
msgboxText{2} = strcat('blah blah',{' '},'45')
msgboxText =
'blah blas' {1x1 cell}
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!