How to run guide gui in a loop
13 次查看(过去 30 天)
显示 更早的评论
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 个评论
Adam
2019-1-11
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.
回答(1 个)
Jan
2019-1-11
编辑:Jan
2019-1-11
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 个评论
另请参阅
类别
在 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!