Pop up menu condition push button
Ältere Kommentare anzeigen
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 Kommentare
Adam Danz
am 22 Mai 2020
If you'd like to use the approach in my answer, it would be easy to adapt it to GUIDE. Let me know if you have a specific question about how to do that.
Pneu 94
am 22 Mai 2020
Adam Danz
am 22 Mai 2020
See my updated answer. Importantly, you'll have to change the handles to match your handle names.
Akzeptierte Antwort
Weitere Antworten (1)
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)
Kategorien
Mehr zu App Building finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!