Trying to open a new pannel when checkboxes are filled but dont work
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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
댓글 수: 2
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 Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!