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

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 17 Nov. 2016
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 Kommentare
matlabnewby
matlabnewby am 17 Nov. 2016
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 am 17 Nov. 2016
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by