Displaying files using a Listbox
2 ビュー (過去 30 日間)
古いコメントを表示
Using GUIDE, I have a listbox that I wish to use to display a folder of files, then have the user select a file from the box, then click another pushbutton to run the selected file. I was looking at http://www.mathworks.com/help/techdoc/creating_guis/f6-7446.html#f6-11263 but was confused where the path to the directory goes or how I add that.
Under the section Specifying the Directory, I see list_box('create','path_to_folder') but am unsure if that is what I'm looking for.
Thanks for the help
0 件のコメント
採用された回答
Matt Fig
2011 年 2 月 25 日
Is the folder of files you wish to display going to be hardcoded into the GUI, or do you wish to have the user select the folder too?
EDIT
Here is an example how to do this. The following code works on my machine. I think you will put the stuff which gets the directory name in the listbox createfcn or the figure creatfcn. I don't use GUIDE anymore so I may be wrong about that. Give it a try and let me know what happens. Note, I commended the lines of importance to your problem.
function [] = GUI_LST_DIR()
S.fh = figure('units','pixels',...
'position',[500 500 200 260],...
'menubar','none',...
'name','GUI_1',...
'numbertitle','off',...
'resize','off');
D = dir('C:\Users\matt fig\Documents\MATLAB'); % Here put your dir name.
D = {D(:).name};
D = D(~cellfun('isempty',strfind(D,'m')));
S.ls = uicontrol('style','list',...
'unit','pix',...
'position',[10 60 180 180],...
'min',0,'max',2,...
'fontsize',14,...
'string',D); % Populate the string with D.
S.pb = uicontrol('style','push',...
'units','pix',...
'position',[10 10 180 40],...
'fontsize',14,...
'string','Run File',...
'callback',{@pb_call,S});
function [] = pb_call(varargin)
% Callback for pushbutton, runs the selected M-File
S = varargin{3}; % Don't worry about this in GUIDE GUI.
% Instead of S.ls, use GUIDATA to get handle to listbox
C = get(S.ls,{'string','value'});
mfl = C{1}(C{2}); % The M-File string name.
eval(mfl{1}(1:end-2)) % Run the M-File
3 件のコメント
Matt Fig
2011 年 2 月 25 日
I just checked by making a GUIDE GUI, and the D creation code does go in the CreateFcn. Just make D like I showed, then put the line:
set(hObject,'string',D)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!