This simple code handles the problem where MATLAB interfaces with an external program that itself writes to a data file. The 3-line use of this code is as follows:
(1) call external code (usually via system command)
(2) call sim_runtime(...)
(3) call subsequent statements
The subsequent statements will not be executed until the external program has finished writing to the external file of interest.
The algorithm is simple: MATLAB is stuck in an infinite while loop that checks to see whether the end of file character has changed in the file the external code is writing to. This requires some user knowledge of the external program: both the time taken to open the external file for writing and a rough estimate of the time taken between subsequent writes to that file.
The subsequent statements following sim_runtime(...) in the main MATLAB code can be used to post-process the recently written file, a different file, or do anything else.
Steven (2023). Pause MATLAB when running external simulation that writes to file (https://www.mathworks.com/matlabcentral/fileexchange/34895-pause-matlab-when-running-external-simulation-that-writes-to-file), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!