Displaying files using a Listbox
조회 수: 3 (최근 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!