GUI edit text and msgbox problem .. what do I miss

조회 수: 16 (최근 30일)
Lex
Lex 2011년 6월 12일
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

채택된 답변

Matt Fig
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}
  댓글 수: 1
Lex
Lex 2011년 6월 12일
Thank you mr. Fig :) It worked well even althrough that first conversion was needed. Because It secures field from String valuse.
So I've splitted field to two inputs ;p Input1 is converted to strink and tested for emptyness and after Else statement there is one more input2 where was conv. problem.
THANKS once again! (I'm new a guy to GUI :P )

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by