How to run guide gui in a loop
13 views (last 30 days)
Show older comments
Hello,
I havent worked with GUIDE before but basically I have a GUI that was created using GUIDE by a person who isnt here anymore and I'm trying to figure out how to integrate it into my script. The GUI takes in 3 individual files and require the operator to click two buttons before it analyze/process those files. I have a bunch of files that I would like to process with a loop and I've read that I can use the set function but I'm unable to get it working. Please let me know what I'm doing wrong with my script below. Thanks for your help!
Main script to batch process files
% Get all the files
files = dir('*.txt');
for i = 1:length(files)
% Call and run the GUI script processfiles.m
processfiles.m
% Pass the files to processfiles.m GUI
set(handles.import_run_Callback, 'String', files(i));
% Wait for GUI to finish reading/processing the file
pause(30)
end
The file import function in my processfiles.m GUI is
% --- Executes on button press in import_run.
function import_run_Callback(hObject, eventdata, handles)
%%codes to analyze the files%%
end
2 Comments
Jan
on 11 Jan 2019
Edited: Jan
on 11 Jan 2019
You forgot to mention, what the problem is. "I'm unable to get it working" does not reveal, what's going on. We see a part of the code only, so we cannot guess, what it should do and what you observe instead. Please edit the question and add more details.
Adam
on 11 Jan 2019
Launching a GUIDE GUI in a loop sounds like a very bad idea. Usually if you want to work with files from a GUI you would either initialise the GUI with them (via the OpeningFcn) or load them manually within the GUI, but the nature of a GUI suggests human interaction which can take an unknown amount of time so pausing for 30 seconds before keep launching new versions of the GUI (assuming you have set it to allow non-singleton behaviour or even if you haven't) will result in a mess.
Answers (1)
Jan
on 11 Jan 2019
Edited: Jan
on 11 Jan 2019
Some bold guesses:
files(i) is a struct and not a string. Try this:
filename = fullfile(files(i).folder, files(i).name);
set(handles.import_run_Callback, 'String', filename);
Calling "processfiles.m" tries to access the field "m" of the struct "processfiles". I assume, that this is the name of a script or function? Then use:
processfiles; % without .m
You cannot access the handles struct globally. Does processfiles reply the handle of the GUI? Then:
GuiH = processfiles;
handles = guidata(GuiH);
set(handles.import_run_Callback, 'String', seeAbove);
Instead of waiting for 30 seconds, it is easier to trigger the access inside the GUI, e.g. by calling a callback, and wait until this process has finished.
0 Comments
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!