Pop up menu condition push button
20 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Pneu 94
il 22 Mag 2020
Commentato: Image Analyst
il 24 Mag 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 Commenti
Adam Danz
il 22 Mag 2020
See my updated answer. Importantly, you'll have to change the handles to match your handle names.
Risposta accettata
Image Analyst
il 22 Mag 2020
Modificato: Image Analyst
il 22 Mag 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 Commenti
Adam Danz
il 24 Mag 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
Più risposte (1)
Adam Danz
il 22 Mag 2020
Modificato: Adam Danz
il 22 Mag 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)
0 Commenti
Vedere anche
Categorie
Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!