how to write If-else statement in GUI Matlab?

13 views (last 30 days)
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')

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 13 Jun 2015
Edited: Azzi Abdelmalek on 13 Jun 2015
% --- 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
  1 Comment
Ahmad Farhan
Ahmad Farhan on 13 Jun 2015
thank u.. i thought the way i write the 'expression' is wrong..

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks 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!