Pop up menu condition push button

20 visualizaciones (últimos 30 días)
Pneu  94
Pneu 94 el 22 de Mayo de 2020
Comentada: Image Analyst el 24 de Mayo de 2020
Hello,
I've 4 popup menu and 1 push button,
I want to, once i choise the 1st value in popup1, the 1st one in popup2, the 1st in popup3 and the 1st in popup4, the push button will be Enable.
Thanks,
  4 comentarios
Pneu  94
Pneu 94 el 22 de Mayo de 2020
I really begin in Gui, so I don't know a lot of things, My problem is to enable a push button after the 4 conditions of the pop buttons are set Thanks
Adam Danz
Adam Danz el 22 de Mayo de 2020
See my updated answer. Importantly, you'll have to change the handles to match your handle names.

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 22 de Mayo de 2020
Editada: Image Analyst el 22 de Mayo de 2020
Try this (assuming GUIDE - replace handles with app if using AppDesigner)
if handles.popup1.Value == 1 && handles.popup2.Value == 1 && handles.popup3.Value == 1 && handles.popup4.Value == 1
handles.button1.Enable = 'on';
else
handles.button1.Enable = 'off';
end
  12 comentarios
Adam Danz
Adam Danz el 24 de Mayo de 2020
I use guidata() to set and retrieve values from non-graphic-handle variables stored somehwere in the app or if I want to add a field to the handles structure in GUIDE GUIs.
Example,
f = figure();
data.a = 9999;
guidata(f,data)
localFunc(f);
disp(guidata(f))
function localFunc(f)
% Add 1 to data.a
data = guidata(f);
data.a = data.a + 1;
guidata(f,data)
end
Image Analyst
Image Analyst el 24 de Mayo de 2020
OK, makes sense. Thanks.

Iniciar sesión para comentar.

Más respuestas (1)

Adam Danz
Adam Danz el 22 de Mayo de 2020
Editada: Adam Danz el 22 de Mayo de 2020
Each of the popup menus should have a callback function that checks the selection of all 4 popup menus. Use a conditional statement that enables the push button when the selection of each popup menu is 1.
For AppDesigner:
I assume the 'popup menu' is what Matlab calls a 'Drop down' menu.
Step 1: create a new function in the app that checks all of the dropdown menus.
From Code View > Code Browser > Functions, select the gree "+" to add this function. You must replace app.DropDown with your handles.
function checkAllDropDownMenus(app)
% Get values of all DropDown menus
getValueIdx = @(h)find(strcmp(h.Items, h.Value));
idx1 = getValueIdx(app.DropDown);
idx2 = getValueIdx(app.DropDown2);
idx3 = getValueIdx(app.DropDown3);
idx4 = getValueIdx(app.DropDown4);
% If all selections are 1, enable button
if isequal(1,idx1,idx2,idx3,idx4)
app.Button.Enable = 'on';
end
end
Step 2: assign a ValueChangedFcn to each drop down menu
The ValueChangedFcn for each dropdown menu should appear as below plus any other code you may already have for the callback function.
% Value changed function: DropDown
function DropDownValueChanged(app, event)
checkAllDropDownMenus(app);
end
For GUIDE GUIs the 2 steps would look like this
Step 1: add this function anywhere in your GUIDE GUI m-file. Replace the handles with your handle names.
function checkAllDropDownMenus(handles)
% Get values of all DropDown menus
idx1 = handles.popupmenu1.Value;
idx2 = handles.popupmenu2.Value;
idx3 = handles.popupmenu3.Value;
idx4 = handles.popupmenu4.Value;
% If all selections are 1, enable button
if isequal(1,idx1,idx2,idx3,idx4)
handles.pushbutton1.Enable = 'on';
end
Step 2: Each popup menu should have a callback function that you add from within GUIDE by right-clicking the popup menu > View Callbacks > Callback. That will add a function to your m-file if it doesn't already exist. Edit the added function so it appears as below.
function popupmenu1_Callback(hObject, eventdata, handles)
checkAllDropDownMenus(handles)

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by