File Exchange

image thumbnail

Real-Time Pacer for Simulink

version (18.7 KB) by Gautam Vallabha
Simulink block for forcing a simulation to run in real (wall clock) time


Updated 01 Sep 2016

View Version History

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

The RealTime Pacer block slows down ("paces") simulation time so that it synchronizes with real elapsed time. The degree of slowdown is controllable via a Speedup parameter.
1) The block is implemented using an M S-function, so it works on any supported Simulink platform. It does not support code generation.

2) The block uses the MATLAB PAUSE function to slow down the simulation. The PAUSE command gives up the processor during the pause, so system performance does not degrade.

3) The M-S function illustrates how to use nested functions to simplify the code.

The matching between simulation time and elapsed real time is approximate, with expected differences on the order of 10 to 30 milliseconds. This limitation is due to difficulties of precise timing with a multitasking operating system.


The following FX entries also implement "real time" functionality for Simulink. They are based on C S-functions and therefore support code generation.

* Simulink Real Time Execution (Real-Time Slower) (Filex# 21908)
* Real-Time Blockset 7.1 for Simulink (Filex# 3175)
* RTsync Blockset (Filex# 24975)

Cite As

Gautam Vallabha (2021). Real-Time Pacer for Simulink (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (52)


Comment est ce qu'on l'utilise ?

how are you supposed to install that...

Schwamm Witali

j b

Berend van den Berg

Hossein Rezazadeh

Does not work in external mode

Matthew Gordon

Kai Zhao

Tobias Kull

The buildt-in simulation pacing of R2018a does not work for me, while this file is working! Thanks

lunkai xiang


Deepak Devendran

Excellent! Works perfectly

Ajith Shenoy

It would be nice, if we could change the speedup value in Real Time.
I am seeding a fault in the model. At the beginning it should run in accelerated mode (speedup = inf), but after sometime at real time (speedup = 1)


Could you explain how to install this package?


Could you explain how to install this package?, thanks you!

Pramod Chaudhary

works fine


good work!

Severin K

Works fine with R2016b, thanks for sharing!

Amit Kumar

Very nice!

Raoul Dominique

could anybody tell me in wich folder i should copy the files ?



It helped me in making simulations for "marketing" or "know-how sharing" purposes

Michael Wagner

Nice work.
Should be part of the standard Simulink libraries.
It does run with Linux

Damjan Miklic

Simple and efficient, works as advertised.

The MATLAB Command Window gets blocked in each step while simulation is running. Is there any way to avoid that?

Tasfin Mahmud

Worked nice for me. Thanks a lot.

Vilian Petkov

Was very useful for me, works as far as I can tell.


Big thanks, simple to use and works great for what I want to do!

Roshan Sharma

Great work! Thanks a lot...
This file exchange is a superb substitution to the real time kernel. It works for me just great. I use it to read/write data from NI-USB 6003 from National Instruments along with the MPC toolbox.
I used to use the "real-time sync" block from Simulink Desktop real-time toolbox provided by Mathworks, with real time kernel. But I (and many others) have a huge problem with it. The CPU usage was always 100% with the fan running at the top speed. The problem continued even when the real time kernel was uninstalled and MATLAB was uninstalled. Restarting computer did not help. Task manger becomes unmanageable. The only work-around was to create a restore point and restore the PC to earlier working state.

Thanks to this simple solution. Now I do not have to worry about restoring my PC.



Thank you! I spent forever screwing around trying to get something that plays back close to real-time, for visualization purposes. What a pain in the posterior for something so simple.

Your block did the job, no problems whatsoever. Cheers!

Karthiga Mahalingam

Great work!

But I have to run a stepper motor using matlab and arduino and I get the following error message: The corresponding 'msfun_realtime_elapsed.tlc' file for the MATLAB S-function 'msfun_realtime_elapsed' in block 'realtime_pacer_example/Elapsed Real Time1' must be located in the current working directory, the MATLAB S-function directory 'C:\Users\ShreeKarthiga\Desktop', or the directory 'C:\Users\ShreeKarthiga\Desktop\tlc_c'.
Is there any way out of this.

Jon Eskils


Best real-time block implementation (tried 5 others that failed to work).
The only one that I've seen with a good readme, and great functionality for custom timing.


Gabriel H

Mateus Antonio

Mikel Iturbe

Despite a previous comment claiming that it does not work on Linux, I was able to run the example and use it in my simulations with Matlab 2016a on Ubuntu 16.04, out of the box.

Dinart Braga

Gautam, thank you very much.
Your code solved my problem in 1 minute.

Also, your install instructions could not be simpler. Nice job!

Pan Song

works fine with me:)

sagar pawar

please guide me....for using this blocks for speed control of dc motor with arduino with matlab...

Alon Tuchner

Works very well.

Kenneth De Leener

Thanks much appreciated

Michael Rice

I have MAC OS X Yosemite. This solutions did exactly what I wanted. Thank you for making this robust enough to work on multiple platforms over multiple releases.

Krisando lalal

Hey, thanks!
I have problem with setting the path.
There are any blocks in simulink library after adding the path.
I simply put the whole folder to /Users/Myusername/Documents/MATLAB/realtimeP
realtimeP - folder with m, s files and models.

and i run addpath('/User/Myusername/Documents/MATLAB/realtimeP')

I have MAC OS X, I would be gratefull for answer :)

Chethan Pandarinath

Thanks, this worked well for me.


Hi it don't runs in linux

Pramit Biswas

Elapsed real time is what I'm searching for. Very nice implementation. Superb.

Thank you very much for sharing.

Pieter Mosterman

Great functionality. Does exactly what I was looking for, including scaled real time. Perfect. Thanks so much, Gautam!

Jeff Orchard

Nice. It does exactly what I want, and it was simple to use. Thanks!


This pacer for Labview works very well for slowing a SIMULINK developed control system to match the timing of a real time device. We are using it to provide control logic to a LabView DAQ system which then controls a hydraulic pump and motor system. To overcome the problem of Microsoft Operating System interrupts, we have added memory to the control system to account for the time losses.


Very nice work!

MATLAB Release Compatibility
Created with R2008b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!