Pause MATLAB when running external simulation that writes to file

Prevents MATLAB executing subsequent statement after an external program is called.

You are now following this Submission

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 (2026). 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 .

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0.0