0
votes

I have a main form GUI that spawns child GUI's which are all modular and independent from the master that spawned it, taking only input arguments, but no output arguments or data dependency as they perform seperate non related tasks.

The current setup is that by pressing a pushbutton on the master GUI, a child GUI is made and performs a computationally long algorithm and will continue until finished, where the GUI is then destroyed.

The problem is I would like the ability to open multiple different modules from the master GUI while a child already exists. For example, press a pushbutton to run GUI 1, go back to master GUI and press another button to run GUI 2, and so on. The issue I encounter is that GUI 1 is then interrupted and on hold until GUI 2 is finished execution, then GUI 1 returns from where it left off, where as I wanted them to both be running simultaneously.

EDIT: I solved my problem, turns out there is an ugly way to do this, and even then, it does not pop up the GUI, but does what I need it to do. Just gotta use parfor with the iteration acting as an index number to tell matlab which function to run inside the loop.

1
Did you try adding calls to pause as I suggested? This should allow the additional windows to appeargrantnz

1 Answers

0
votes

You can do rudimentary parallel processing by using the pause command to yield execution but this is a bit intrusive as your long algorithm would need to periodically call pause.

function [ output_args ] = BackgroundTask( srcTimer,~, hObject )
%BackgroundTask - Test background task

fprintf(1,'Background\n');

end


 hObject = 'Some relevant Object';
 feedbackTimer = timer('Period',1,'TimerFcn', {@BackgroundTask, hObject}, 'ExecutionMode','FixedRate' );
 start(feedbackTimer);

Long running task

 fprintf(1,'Start\n'); 
 for i=1:200000; factorial(100); 
        if mod(i,1000) == 0
            pause(0.001); 
        end
 end
 fprintf(1,'Finish\n');

If you start the background task and then run the long running code you should see:

Background
Background
Start
Background
Background
Background
Background
Background
Finish
Background
Background

It may also be worth looking into the Matlab Parallel Computing Toolbox.