Working with Popup Menu in GUIDE
Show older comments
Dear Support,
Please how can I link data from one Popup menu to the other. Example Popup Menu1: city1, city2, city3 Popup Menu2: Categories of City1, City2
city1 variables: area, population, language and same for city2 and so fort.
I wish to know how I can program Popup menu2 to list the categories of cities after selecting from Popup Menu1. i.e. I select city1 in Popup Menu1 I want Pop Menu2 to list categories of City1: e.g. area, population, language
Thanks
Answers (1)
Geoff Hayes
on 26 Feb 2018
Perez - use the callback function for the popup menu 1 button to update the categories in popup menu2. For example,
function popupmenu1_Callback(hObject, eventdata, handles)
% get the list of all cities
allCities = get(hObject,'String');
% get the selected city
selectedCity = allCities(get(hObject, 'Value'));
% given the city name, update the other popup menu accordingly
if strcmp(selectedCity, 'Ottawa')
set(handles.popupmenu2,'String',{'value1','value2','value3'});
elseif strcmp(selectedCity, 'Montreal')
set(handles.popupmenu2,'String',{'value11','value22','value33'});
end
The above example assumes that there are two cities in the first popup menu named Ottawa and Montreal. Once the user selects one of these cities, this callback fires and we then update the other popup menu with the categories for that city.
Categories
Find more on Desktop in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!