View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Simulink® Real Time Execution

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

4.7 | 15 ratings Rate this file 97 Downloads (last 30 days) File Size: 20.4 KB File ID: #21908 Version:
image thumbnail

Simulink® Real Time Execution


Guy Rouleau (view profile)


27 Oct 2008 (Updated )

C-MEX S-function that reduces the execution speed of a model close to real time

| Watch this File

File Information

This block should be used only to reduce the speed of a Simulink® model so that it can be observed running in real time. If the simulation is already slower than real time, this block has no effect.
To use it, extract the files to a directory on the MATLAB path. Re-open the Simulink browser and you should see a new library named "Useful Stuff" which contains one block named "Real-Time Subsystem". Place this block in a model to use it.

To use this file under other operating systems, just run "mex sfun_time.c" to generate the MEX-file for your platform

For accurate hard real-time, I recommend looking at xPC Target or Real-Time Windows Target.


This file inspired Simulink Block For Real Time Execution and The Curling Game.

Required Products Simulink
MATLAB release MATLAB 7.7 (R2008b)
Other requirements You will need to re-mex the s-function for other platforms.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (26)
01 Nov 2016 Wu Jun

Wu Jun (view profile)

Good work. Easy to use in 32-bit 2010a version.

It can not be used in 64-bit version. The problem may lies in the 64-bit compiler, which is hard for new users like me.

14 Oct 2016 Nathan

Nathan (view profile)

The zip file appears to be corrupted. All I get is an empty license.exe file.

Comment only
17 Feb 2016 mohamed elganiny


plz , i have an question , if i have an algorithm writing by m.files matlab code and i want to call this algorithm to simulink model

note : this algorithm written by no of m.files in one folder


17 Feb 2016 Steve Miller

Steve Miller (view profile)

Great work, Guy. Very useful. Even six years and 12 MATLAB releases later, it works perfectly.

26 Jan 2016 Doni Yusdinar

really nice..

15 Dec 2014 Chethan Pandarinath

I appreciate the effort, unfortunately I could not get this to work myself. I ended up having good luck with the "Real-Time Pacer for Simulink" block:

20 Nov 2014 Ra1209k

Can someone please tell where is the exact location to extract the files?

Comment only
02 Jun 2014 Xavier Creus

Should I change the "Time Scaling Factor" to adapt it to work in "Real Time"?
With "1" it works to slow and with "0" it works to fast... How can I adjust the correct value?

Comment only
24 May 2013 Harol Herrera

How do I find the directory path

Comment only
28 Nov 2012 teoman

teoman (view profile)

how can i implement to my model?

Comment only
28 Nov 2012 teoman

teoman (view profile)

11 Jun 2012 Erçin

Erçin (view profile)

I have 64 Bit Operation System and "mex sfun_time.c" file doesn't have execute or compile button in M-File or Microsoft Visual Studio. Please help me...

Comment only
21 May 2012 zhao gang  
17 Apr 2012 sabahat

In rtc_example.mdl, when i set the solver setting to fixed step size and discrete time, and sample time to (1/70), it does not work in real time, do you have an idea to fix this?

Comment only
05 Apr 2012 transparency

Is this also working for R2010b on a Linux Machine?

Comment only
19 Jan 2012 Mark

Mark (view profile)

I am not seeing the "Useful Stuff" library pop up. Do you expect problems running this on 2010b (XP,32 bit)? Thanks!

Comment only
10 Jan 2012 Sun

Sun (view profile)

07 Jan 2012 sufendi mulia

i have try to run your file and it's work fine. but the problem is, the simulation run to slow compare to real time after i add your function in my simulink project.
the question is, can i make it run faster so it run same as real time ? and how to make it.


12 Oct 2011 BenSC63  
06 Oct 2011 Guillaume MARTIN

Simple, efficient : what I needed !

25 Aug 2011 James

James (view profile)

24 Mar 2011 Guy Rouleau

Guy Rouleau (view profile)

Harrison, if you are not using a Windows 32-bit system, you need to execute "mex sfun_time.c" to generate the MEX-file. Note that if you never used MEX before, you will need to execute "mex -setup" to choose a compiler.

Comment only
24 Mar 2011 Harrison Yiu

I am sorry that i can execute this file ,
the error is showned :
Error in S-function 'rtc_example/Soft Real Time': S-Function 'sfun_time' does not exist.

How can i solve this problem ?
I have already linked to directory on the MATLAB path.

Thanks a lot , I am now using R2008a

Comment only
18 Jan 2011 Tan Edwin

problem solved and it runs well

22 Jul 2010 Lukas Lansky

Very nice.

03 Jul 2009 Andreas

Fantastic!!! And so easy to use!!!!

08 Jan 2009 1.1

Updated to allow scaling of time. It is now possible to specify that one second of simulation is X seconds in real life.

26 Feb 2009 1.2

To use this file under other operating systems, just run "mex sfun_time.c" to generate the MEX-file for your platform

18 Jun 2009 1.3

Minor modif for BSD license

21 Jul 2010 1.4

- Fixed a bug causing the model to freeze after 36 minutes on some Unix systems.
- Possible to tune the Time Scaling Factor while the simulation is running.
- Possible to pause and restart the simulation.

22 Jul 2010 1.5

Fixed bug causing the model to freeze after 36 minutes on Linux 32-bit systems

01 Sep 2016

Updated license

Contact us