How to run guide gui in a loop

조회 수: 13 (최근 30일)
Max Bernstein
Max Bernstein 2019년 1월 10일
댓글: Adam 2019년 1월 11일
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
Jan
Jan 2019년 1월 11일
편집: Jan 2019년 1월 11일
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
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
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.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by