how to populate a pop-up menu with variable selections

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

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.
Yes, I want the file names as the options in the pop-up menu so that the GUI will operate on the data associated with the file name. I tried using Guide and App Designer and then tried to modify the code generated by them to use a variable Cell Array vs. a hard coded list.
@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.
Adam Danz
Adam Danz le 17 Juin 2019
Modifié(e) : Adam Danz le 17 Juin 2019
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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur File Operations dans Centre d'aide et File Exchange

Modifié(e) :

le 17 Juin 2019

Community Treasure Hunt

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

Start Hunting!

Translated by