Trying to open a new pannel when checkboxes are filled but dont work

조회 수: 1 (최근 30일)
matlabnewby
matlabnewby 2016년 11월 13일
댓글: Geoff Hayes 2016년 11월 17일
Hello guys, here I am trying to create a gui with different checkbox associated with a measurement. you hae 2 main cheboxes. Each of them have specefic checkboxes that are available to be filled with a value. If measurements are missing (depending if the first or second cehcbox is selected), I want to open a msgbox that tells to go back. If the statements are met, i want to open a new pannel.
Tahnk you in advance!
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
L = str2double(get(handles.editL,'String'));
G = str2double(get(handles.editG,'String'));
W = str2double(get(handles.editW,'String'));
S = str2double(get(handles.editS, 'String'));
C = str2double(get(handles.editC,'String'));
H = str2double(get(handles.editH,'String'));
checkboxgable = get(handles.checkboxStatus2,'Value');
checkboxtunnel = get(handles.checkboxStatus1,'Value');
switch checkboxgable
case checkboxgable == 1
if isempty(L)
disp('There is no valid values for the length of the house (L)');
elseif isempty(G)
disp('There is no valid values for the height (G)');
elseif isempty(W)
disp('There is no valid values for the width');
elseif isempty(S)
disp('There is no valid values for the length of roof (S)');
elseif isempty(H)
disp('There is no valid values for the Total height (h)');
end
case checkboxgable == 0 && checkbotunnel == 0
disp('you cannot continue without filling the required measurements')
case checkboxtunnel == 1
if isempty(L)
disp('There is no valid values for the length of the house (L)');
elseif isempty(W)
disp('There is no valid values for the width (W)');
elseif isempty(H)
disp('There is no valid values for the total height (h)');
elseif isempty(C)
disp('There is no valid values for the length of roof (C)');
end
otherwise
window2
end

채택된 답변

Geoff Hayes
Geoff Hayes 2016년 11월 17일
You are treating your case statements as if they are conditions
case checkboxgable == 1
or
case checkboxgable == 0 && checkbotunnel == 0
I think that using if and elseif would be more suitable for this type of work. For example
if checkboxgable == 1
% do something
elseif checkboxgable == 0 && checkbotunnel == 0
% do something else
elseif checkboxtunnel == 1
% etc.
else
% etc.
end
See switch for details on use of this expression type.
  댓글 수: 2
matlabnewby
matlabnewby 2016년 11월 17일
Thank you Geoff for your contribution!
But i was wondering if in that case, I could use "if statement" insides actual "if statements"? That's why I wanted to use switch, but i will take a closer look!
Have a good one!
Geoff Hayes
Geoff Hayes 2016년 11월 17일
Yes, you can use if statements within another if like
if x==2
if y == 3
% do something
else
% do something else
end
else
if y == 4
% do something
elseif y > 4
% do something
else
% do something
end
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by