how to populate a pop-up menu with variable selections
Afficher commentaires plus anciens
I want to make a gui with a pop-up menupop-up menu with selections that are generated from a directory of files.
4 commentaires
Geoff Hayes
le 17 Juin 2019
Bruce - are the file names used as options in the pop-up menu? Are you using GUIDE, App Designer, or programmatically creating your GUI? Please provide more details.
Bruce McVicker
le 17 Juin 2019
Jan
le 17 Juin 2019
@Bruce: It matters if the GUI is created by GUIDE or by AppDesigner or programmatically. In these cases there are different locations where the code must be inserted. Actually the code is easy:
FileList = dir(fullfile(Folder, '*.*'));
NameList = {FileList.name};
PathList = fullfile({FileList.folder}, NameList);
handles.popup1.String = PathList; % Or Name list, as you want
But this matchs the GUIDE approach. With AppDesigner the needed handle of the popup menu is not in handles.popup1. So please give us a chance to answer your question and add some details.
I've used guide, app designer, and the programmatic approach and as long as your GUI is simple, containing just a few component, I recommend the programmatic approach because it's simpler to read the code and you'll learn a lot more.
Here's a way to get a list of files from your current directory and put them into a popup menu. You can run this code to try it yourself.
dirContent = dir(cd); %replace cd with a directory
filelist = {dirContent.name}'; %list all content
filelist([dirContent.isdir]) = []; %remove directories
f = figure();
uih = uicontrol(f,'Style','PopupMenu','Units','Normalize','Position',[.1 .1 .5 .7],...
'String',filelist);
You can see in my call to uicontrol() I've set a bunch of parameter but there are lots more (including callback functions). See the complete list and descriptions here.
Réponses (0)
Catégories
En savoir plus sur File Operations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!