Create drop downs dynamically from file input
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am working on creating an application in app designer and part of it requires me to read a set of data from a file and create dropdowns from the content of the files. So, the file contains what the dropdown should be and what the dropdown options should be. Is it possible to do something like this...without knowing the drop downs or how many there is going to be until the file is read?
I was trying to do something like this where I store the drop down items inside an array, but it doesn't seem to work. I get an error that dot indexing is not supported for variable of thsi type. And looking in the workspace, app.presetDropdown(i) isn't even a drop down item, but a double...which is confusing.
for i=1:length(A)
app.presetDropdown(i) = uidropdown;
app.presetDropdown(i).FontSize = 16;
...
0 commentaires
Réponses (1)
Vedant Shah
le 18 Juin 2025
The MATLAB App Designer application here requires the dynamic generation of dropdown menus based on file input. The file typically specifies both the number of dropdowns and their respective options, which are not known beforehand.
In dynamic creation of dropdown components in MATLAB App Designer, ensure that the storage structure is compatible with UI objects. If ‘app.presetDropdown’ is not explicitly declared as a cell array or object array, MATLAB may default to interpreting it as a numeric array, resulting in errors such as:
"Dot indexing is not supported for variables of this type."
To correctly store and manage multiple dropdowns, a cell array should be used, as UI components are object handles. The following code snippet demonstrates an approach for the same:
app.presetDropdown = cell(1, length(A));
for i = 1:length(A)
dd = uidropdown(app.UIFigure);
dd.FontSize = 16;
dd.Items = A{i};
dd.Position = [100, 300 - (i-1)*50, 150, 22];
app.presetDropdown{i} = dd;
end
This approach ensures that each dropdown is created and positioned distinctly. It also assumes that the variable A contains a cell array of item lists, one for each dropdown.
For more information, refer to the following documentations:
0 commentaires
Voir également
Catégories
En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!