Using Matlab apps sequentially in a loop

조회 수: 10 (최근 30일)
Jonathan
Jonathan 2019년 8월 29일
댓글: Josa 2020년 3월 26일
I'd like to use different Matlab apps in a loop where the loop waits for the application to finish. A specific example would be to review and threshold images in a directory using the imageSegmenter app. Something like:
files = dir('*.bmp');
for f=1:length(files)
im = imread(files(f).name);
BW = [];
imageSegmenter(im);
if ~isempty(BW)
% Save the mask.
end
end
But, if I have 10 images in the directory, that will spawn 10 instances of imageSegmenter. With many images, this is simply impractical.
I've looked at uiwait and waitfor, but these do not work with apps (as best I can tell). Putting pause(0) after the call doesn't help either.
Any help or ideas here would be greatly appreciated. Thanks in advance.
  댓글 수: 2
Jonathan
Jonathan 2019년 8월 30일
Sorry, I did not use pause(0), that was just typing from memory and meant 'pause'. Yet pause alone, breakpoints, etc nothing allows you to run these things sequentially. Are Matlab apps designed to be essentially autonomous? Why can one not get some handle on them to allow execution of something - i.e., scripts - to wait until completion. It seems a simple thing to require.
Josa
Josa 2020년 3월 26일
Hi Jonathan, I am facing exactly the same problem, did you manage to segmentate images sequentially?

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2019년 8월 31일
Are Matlab apps designed to be essentially autonomous?
Yes, they create new non-modal GUI figures, and like any other MATLAB figures, they work on callbacks.
Why can one not get some handle on them to allow execution of something - i.e., scripts - to wait until completion.
You can, for some of them, if you know what you are looking for.
set(groot, 'Showhiddenhandles', true);
fig = findobj(groot, 'name', 'Segmentation');
Now you can waitfor(fig) . This does, however, require that you close the app each time
  댓글 수: 1
Jonathan
Jonathan 2019년 9월 3일
Many thanks for this response Walter. This is exactly what I am looking for, but the only issue currently is that this doesn't give the handle to the imageSegmenter. It could be that the name parameter is incorrect.
Matlab technical support are helping me on this one, so I will post the answer if they find a solution.
Again, thanks for the response. Much appreciated.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by