I'm making a GUI in MATLAB that will accept numerical inputs from the user and make calculatations with them accordingly. I want to be able to create an error dialog box whenever the user enters letters instead of numbers. So far I have this bit of code to display the error message:
ed = errordlg('Please enter numbers only','Error'); set(ed, 'WindowStyle', 'modal');uiwait(ed);
And this is a section of the main code that I would like to integrate the error message in:
function roofspace_Callback(hObject, eventdata, handles)
aSpace = str2double(get(hObject,'String')); %This is the user entered value for the roofspace.
set(hObject,'UserData',aSpace);
if aSpace==0 %If aSpace does not have anything then nothing is enabled.
set(findall(handles.uipanelFunds, '-property', 'enable'), 'enable', 'off');
set(findall(handles.uipanelPanels, '-property', 'enable'), 'enable', 'off');
set(findall(handles.uipanelUsage, '-property', 'enable'), 'enable', 'off');
set(handles.calculate,'enable','off');
set(hObject,'String','');
else %If aSpace hs a value then this enables the rest of the inputs.
set(findall(handles.uipanelFunds, '-property', 'enable'), 'enable', 'on');
set(findall(handles.uipanelPanels, '-property', 'enable'), 'enable', 'on');
set(findall(handles.uipanelUsage, '-property', 'enable'), 'enable', 'on');
set(handles.calculate,'enable','on');
end
EDIT: In summary, I need to figure out how I can integrate my error message code into this section of code so that it checks if the user has inputted numbers, otherwise I would like an error message to display. At the moment, the code displays the error message regardless of what the user has inputted.