Wait a boolean variable becomes false
34 views (last 30 days)
I have connected the software Plant Simulation to Matlab and thus when I start the matlab program the simulation on Plant SImulation correctly works. However, after this simulation I have to analyse the data but matlab proceeds even if the simulation is not finished. I am thinking about using the COM-function IsSimulationRunning, which returns true if running and false if not, to say matlab to wait until this variable becomes false.
However I do not know how to do that. This because there should be a dynamic control of this variable to see if it is true or not.
How can I do that? Thanks
Guillaume on 26 Apr 2018
Well, you can always write a while loop that test that the property is false.
%waiting for simulation to complete
%simulation is no longer running
%rest of the code.
However, if your com object triggers an event when the simulation completes, you may want to listen to that event instead. Details of the event would be required to explain how to do that.
More Answers (1)
Alec Jacobson on 10 May 2019
The accepted answer will cause your CPU to spin (wasting precious power and computational resources).
Instead, I found a "hack" that uses a built in function. Create a phony graphics element (e.g., with plot), tell matlab to waitfor it to be deleted and then delete it when you're ready to break out of the loop.
For example, this part of the code will wait for dsh to be deleted.
dsh = plot(nan,nan);
In your other code you can delete the dsh object to break out of the waitfor: