Pause MATLAB when running external simulation that writes to file
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.
Cite As
Steven (2024). 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 Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |