Creating Uicontrol drop down menus with varied selections

조회 수: 11 (최근 30일)
Joseph Mazzella
Joseph Mazzella 2018년 11월 27일
댓글: Joseph Mazzella 2018년 11월 28일
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.
  댓글 수: 1
Joseph Mazzella
Joseph Mazzella 2018년 11월 27일
If the user selects a item from the first popupmenu only I want only certain items of the string of the second popupmenu to show.

댓글을 달려면 로그인하십시오.

채택된 답변

Cris LaPierre
Cris LaPierre 2018년 11월 28일
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
  댓글 수: 11
Cris LaPierre
Cris LaPierre 2018년 11월 28일
Not in a GUI. Code execution all occurs in functions.
Mat files load variables to the workspace, not to a variable. If you want to capture them in the handles structure, you'd have to know what each of those variable names is going to be and manually assign them to the handles structure.
load('Toyota_Dual_VVT_i_1GR_FE_Engine_Specs.mat');
handles.data.var1 = var1;
handles.data.var2 = var2;
...
I'm curious. What are we designing this for? If this is a class project, I'm tempted to step back and let you figure some things out on your own.
Joseph Mazzella
Joseph Mazzella 2018년 11월 28일
It is a personal project that I opted to take up on that will then be used as a class project. I appreciate the help I am just new to the GUI controls of MATLAB.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by