0
我正在MATLAB中制作一个GUI,它将接受来自用户的数字输入并相应地进行计算。我希望能够在用户输入字母而不是数字时创建错误对话框。到目前为止,我有这段代码显示错误消息:Matlab gui错误信息
ed = errordlg('Please enter numbers only','Error'); set(ed, 'WindowStyle', 'modal');uiwait(ed);
而这是主要的一段代码,我想的错误消息集成:
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
编辑: 总之,我需要弄清楚如何将我的错误消息的代码集成到这部分代码,以便它检查,如果用户已输入数字,否则我想显示一条错误消息。目前,无论用户输入什么内容,代码都会显示错误消息。
有些洞察...什么?你的问题是什么? – excaza
@excaza,当用户给出非数字输入时,如何获得此代码以显示错误消息?就目前而言,无论输入什么内容,都会显示错误消息。我不知道如何将错误消息代码集成到程序中以完成此操作 – Oreomega
好像你更关注如何检查用户输入是否是一个数字,而不是在哪里嵌套if循环。 (如果它确实是你的代码,我相信你知道把if语句放在哪里..)。 – BillBokeey