how to write If-else statement in GUI Matlab?

3 次查看(过去 30 天)
hi, I would like to display massage box on a GUI screen based on value of 'sum' operation. i have 2 editBox and user need to enter 2 value on those box. then, i will click on pushbutton called "SUM". based on the answer, if the value is between 0-0.5, the massage box will display "INSECURE". if the answer is between 0.6-1.0, the massage box will display "HIGH". i have write some coding but it can't RUN. can anyone help me? Thanks
% --- Executes on button press in sumbutton.
function sumbutton_Callback(hObject, eventdata, handles)
% hObject handle to testingbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
val = str2num(get(handles.input1,'String')) + str2num(get(handles.input2,'String'));
if (val >= 0 && val <= 0.5)
msgbox('Your System is INSECURE')
if (val >= 0.6 && val <= 1)
msgbox('Your System is SECURE')

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2015-6-13
编辑:Azzi Abdelmalek 2015-6-13
% --- Executes on button press in sumbutton.
function sumbutton_Callback(hObject, eventdata, handles)
% hObject handle to testingbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
val = str2num(get(handles.input1,'String')) + str2num(get(handles.input2,'String'));
if (val >= 0 && val <= 0.5)
msgbox('Your System is INSECURE')
elseif (val >= 0.6 && val <= 1)
msgbox('Your System is SECURE')
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by