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

采纳的回答

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