error with GUI error dialog and inputs...

3 views (last 30 days)
Tula
Tula on 5 Dec 2014
Edited: Geoff Hayes on 7 Dec 2014
I am working on a MATLAB GUI where the user would input data into the edit text boxes and then that data will be displayed in the command window. When a user inputs data that is not a number, an error dialog box should pop up. However, that's not working out. Here is an example of the code I've written so far, followed by the error messages:
-----------------------
CODE:
-------------------------
function Coordinates_Callback(hObject, eventdata, handles)
% hObject handle to Coordinates (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Coordinates as text
% str2double(get(hObject,'String')) returns contents of Coordinates as a double
M=get(hObject,'String');
input=cell2mat(M);
handles.Coordinates=input;
disp(input)
input=str2double(get(hObject,'String'));
if isnan(input)
errordlg('You must enter a numeric value.','Invalid input','modal')
uicontrol(hObject)
return
else
handles.Coordinates=input;
end
----------------------------
ERROR:
------------------
Cell contents reference from a non-cell array object.
Error in cell2mat (line 42)
cellclass = class(c{1});
Error in ME305_GUI>Coordinates_Callback (line 334)
input=cell2mat(M);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in ME305_GUI (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)ME305_GUI('Coordinates_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
--------------------------
suggestions?
  1 Comment
Ben11
Ben11 on 5 Dec 2014
That's because M is not a cell but a string, hence calling cell2mat on a strings throws an error.Since you're calling str2double later I don't see why you would need this line and the one before actually.

Sign in to comment.

Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!