Multiple dropdown inputs to narrow down file options in App Designer

Good morning!
I have been using MATLAB App Designer for two months or so and right now, I am having some troubles using drop downs.
My goal is to have the user choosing 3 different values in 3 different drop downs. By choosing the first value in the first drop down, depending on the available options in the database, the values will adapt in the second drop down and then the user will pick a second value. After the first two values are chosen, the values in the third drop down will adjust again so that the user can choose the value needed. Once the three values are chosen, a different drop down menu otside of this panel will display the files that matches the values chosen by the user so that its data can be uploaded and the data plotted.
Would it be something possible?
Thank you!

 Réponse acceptée

Jon
Jon le 27 Juil 2023
Modifié(e) : Jon le 27 Juil 2023
I have attached a very simple example of how you might have the choice from one drop down menu change the possible choices from a second drop down. In this example initially both drop downs have three items. The first has Choice A, Choice B, Choice C, the second has Choice 1, Choice 2, Choice 3. When you select an item from the first list, the corresponding element is eliminated from the second list. So if you pick Choice B from the first list, the second drop down becomes Choice 1, Choice 3 (Choice 2 is eliminated). Anyhow this is just to illustrate the principle. You can modify with your specific logic.
The key idea is to use the value changed callback from the first drop down, to modify the Items property of the second,
% Code that executes after component creation
function startupFcn(app)
% Define initial drop down item lists
app.DropDown1.Items = {'Choice A','Choice B','Choice C'};
app.DropDown2.Items = {'Choice 1','Choice 2','Choice 3'};
end
% Value changed function: DropDown1
function DropDown1ValueChanged(app, event)
value = app.DropDown1.Value;
% Modify second drop down menu according to choice made here,
% specifically eliminate corresponding drop down item in the
% second list
idx = find(ismember(app.DropDown1.Items,value));
app.DropDown2.Items(idx) = [];
end

4 commentaires

Margaux
Margaux le 27 Juil 2023
Modifié(e) : Margaux le 27 Juil 2023
How does it work? Like if I choose Choice B and then I only get 1 and 3 and if I do it again, I am getting an error that says "Matrix index is out of range"
Yes, you would get an error like that if you do it again. As I said, I just wanted to make a very simple example to show you how the Value Changed callback from the first dropdown modifies the items in the second. In its current form this just works for the first time you make a selection. Obviously you would have to modify this further for real use. I assumed your logic for what you wanted to change based on the first selection was nothing like in my example, so I didn't put much effort into considering what it actually modified, and possible errors, just wanted to show the principle.
Ok makes sense! I'll try to implement that. Thank you!
Good, let me know if you have more questions once you get into the details

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Centre d'aide et File Exchange

Produits

Version

R2023a

Question posée :

le 27 Juil 2023

Commenté :

Jon
le 27 Juil 2023

Community Treasure Hunt

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

Start Hunting!

Translated by