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

9 Ansichten (letzte 30 Tage)
Mathias Wagner
Mathias Wagner am 12 Dez. 2016
Bearbeitet: Adam am 12 Dez. 2016
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

Antworten (1)

Adam
Adam am 12 Dez. 2016
Bearbeitet: Adam am 12 Dez. 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).

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by