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!