double action of GUIDE adapted drop down menu callback
Afficher commentaires plus anciens
In my code, I still have some GUIDE-style callbacks of dropdown menus as follows (this is just example code):
% Value changed function: mydropdown_menu
function mydropdown_menu_Callback(app, event)
% Create GUIDE-style callback args - Added by Migration Tool
[hObject, ~, handles] = convertToGUIDECallbackArguments(app, event);
value = get(hObject,'Value');
if value==7
warndlg('warning message');
end
guidata(hObject, handles);
end
The issue is: when I make choice of value 7, then 'warning message' is displaed as intended, however, when I make next choice of any other value, the 'warning message' is displayed again. I do not have such a problem in Appdesigner-style value changed callbacks. How can I solve this problem?
Réponse acceptée
Plus de réponses (1)
Image Analyst
le 13 Juin 2023
What if you add a "value changed callback" by right clicking on the dropdown list? Then have this
function mydropdown_menu_Callback(app, event)
displayedString = app.mydropdown_menu.Value
selectedIndex = app.mydropdown_menu.Item
if selectedIndex == 7
uiwait(warndlg('warning message'));
end
end
5 commentaires
G A
le 13 Juin 2023
Image Analyst
le 13 Juin 2023
Try making a new dropdown. Copy over all the items from your old GUIDE dropdown and adding a value changed event. Here my drop down was called "DropDown" but yours would be "mydropdown_menuNew" or something like that. Full demo is attached.
% Value changed function: DropDown
function DropDownValueChanged(app, event)
value = app.DropDown.Value % The word in the drop down that is showing.
choices = app.DropDown.Items % List of all the possible choices.
[~, selectedIndex] = ismember(value, choices) % The index of the selected item.
end
G A
le 14 Juin 2023
Catégories
En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!