MATLAB: Opening a file that requires another file for input

fileguilistbox

I have an m-file that requires a .txt file as input in order for the m-file to run.
Something like
Run_Program(FILENAME)
%Run_Program(FILENAME)runs the program based on input commands as
%specified in ./runprogram/FILENAME.
where FILENAME corresponds to the name of the .txt file I wish to use.
I have a GUI (using GUIDE) which contains a listbox and a pushbutton. The listbox contains the .txt files that I can choose from in order to run the m-file. Normally I would just enter the name of the m-file into the pushbutton code to run it, but since the m-file cannot run on its own, and needs the selected file from the listbox, what would the code look like? To try and clarify, I want to run the m-file Run_Program with whichever .txt file is selected from the listbox via the pushbutton

Best Answer

Was it this you were looking for?
function listbox1_callback(src, event, handles)
fileidx = get(src, 'Value');
if isempty(value); return; end
filechoices = cellstr(get(src, 'String'));
thisfile = filechoices(fileidx);
set(src, 'Enable', 'off');
Run_Program(thisfile);
set(src, 'Enable', 'on');
end