how to populate a pop-up menu with variable selections

1 visualización (últimos 30 días)
Bruce McVicker
Bruce McVicker el 17 de Jun. de 2019
Editada: Adam Danz el 17 de Jun. de 2019
I want to make a gui with a pop-up menupop-up menu with selections that are generated from a directory of files.
  4 comentarios
Jan
Jan el 17 de Jun. de 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.
Adam Danz
Adam Danz el 17 de Jun. de 2019
Editada: Adam Danz el 17 de Jun. de 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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Entering Commands en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by