MATLAB: Creating Uicontrol drop down menus with varied selections

MATLABpopupmenuuicontrol

How can you create a uicontrol drop down menu's that are dependent on the selection of the previous menu. Basically I want to be able to have a list of brands then select one and have a list of models and from the brand selection it will only show the models associated to that brand. I am thinking using if statements and a callback but am not sure how to put it all together. Any help would be great thank you.

Best Answer

Are you doing this programmatically, in App Designer or GUIDE?
You can't hide items in a dropdown menu list. You can hide it until a selection is made in another dropdown list and populate its items based on what was selected.
You would use a callback function that will execute when the value is changed.
If I assume App Designer:
% Value changed function: DropDown
function DropDownValueChanged(app, event)
value = app.DropDown.Value;
app.DropDown2.Visible = 1;
switch value
case 'Option 1'
app.DropDown2.Items = {'A','B','C'};
case 'Option 2'
app.DropDown2.Items = {'D','E','F'};
case 'Option 3'
app.DropDown2.Items = {'G','H','I'};
end
end