Opening a file that requires another file for input
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (1)
Matt Fig
il 2 Mar 2011
Get the string in the listbox, and pass it to the function which needs it. In the callback for the pushbutton, you put something like this:
C = get(listboxhandle,{'string','value'}); % Use the handle to the listbox.
mfl = C{1}(C{2}); % The M-File string name.
Run_Program(mfl) % Run the M-File
.
.
.
.
.
.
EDIT
In response to your comment, here is an example on one of my GUIDE GUIS. To figure out what GUIDE called the uicontrols, do this at the command line:
>> H = LISTBOX_EX % Call the GUIDE GUI, return handle.
H =
158.002563476563
>> guidata(H) % This shows the names of the uicontrols.
ans =
figure1: 158.002563476563
listbox1: 0.002685546875
pushbutton1: 159.002563476563
output: 158.002563476563
Now that you know the name of the listbox, in the callback to the pushbutton put this:
H = guidata(gcbo);
C = get(H.listbox1,{'string','value'}); % Use the handle to the listbox.
mfl = C{1}(C{2}); % The M-File string name.
Run_Program(mfl) % Run the M-File
1 Commento
Dave
il 3 Mar 2011
Categorie
Scopri di più su Whos in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!