GUI edit text and msgbox problem .. what do I miss
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Matt Fig
on 12 Jun 2011
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}
More Answers (0)
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!