how to populate a pop-up menu with variable selections
1 回表示 (過去 30 日間)
古いコメントを表示
I want to make a gui with a pop-up menupop-up menu with selections that are generated from a directory of files.
4 件のコメント
Jan
2019 年 6 月 17 日
@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
2019 年 6 月 17 日
編集済み: Adam Danz
2019 年 6 月 17 日
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.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!