Does Matlab wait for the execution of a function in a while loop?

9 views (last 30 days)
Hi everyone,
I got a problem and couldn't find a satisfying answer.
My starting position is:
I have a program which is meant to run forever, so i put everything in a "while 1" loop. This loop queries changes in input data every 5 seconds. If a change occurs, a function is started to handle it. The function has no output, so its termination isn't critical for the code in the loop. It has some input values, but those variables are set before the loop, which means they don't change over time.
My question:
Does Matlab wait for the termination of the function to continue the loop, if a change occurs? I would prefer the function to be called and then to continue the loop, without any regard for the run time of the function.
Cheers, Mathias

Answers (1)

Adam
Adam on 12 Dec 2016
Edited: Adam on 12 Dec 2016
Unless you are kicking it off in a new thread using some form of parallel processing then code will run sequentially and will only return to the while loop when the function tree it has previously entered is completed.
The simple function attached shows that the program remains in the inner loop and does not carry on the outer loop at all. (Note, you'll have to end it with Ctrl C if you run it since it is an infinite loop).

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!