Non blocking while loop in appdesigner?

3 views (last 30 days)
Stefan
Stefan on 19 Nov 2019
I want to create a GUI with a continously running while loop as main processing part, while using callbacks and the matlab command prompt
What I want to do, is Start the GUI, do some initialisation and than start a while loop which processes data as quick as possible. (DAQ is done with a timer).
While in this "MainLoop", I want to be able to react to callbacks and most importantly, I want to be able to continue to use the matlab main window.
While I can react to callbacks, Matlab wont process any inputs to the command line while inside the main loop.
I tried 3 different methods to start the main loop, but none works.
The only thing that works is deleting the while loop as the execution function of a periodic timer, however, this is too slow (and unflexible) for the quite short MainLoop.
Is there a way to keep the command prompt working and not using timers?
MainLoop:
function MainLoop(app)
while ~app.StopFlag
app.ProcessingIteration = app.ProcessingIteration +1;
disp(['Iter: ' num2str(app.ProcessingIteration)]);
pause(0.1)
drawnow limitrate;
end
end
Method 1: Direct Start from startupFcn
function startupFcn(app)
app.MainLoop();
end
Method 2: Starting via One-Shot Timer
function startupFcn(app)
app.Timer = timer('ExecutionMode', 'singleShot','Name','MainLoop','StartDelay',2);
app.Timer.TimerFcn = @(~,~)app.MainLoop();
end
Method 3: Starting via Button Press
function ButtonPushed(app, event)
app.MainLoop();
end

Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!