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

Simulink® Real Time Execution



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 (21)
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?

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?

24 May 2013 Harol Herrera

How do I find the directory path

28 Nov 2012 teoman

how can i implement to my model?

28 Nov 2012 teoman  
11 Jun 2012 Erçin

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...

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?

05 Apr 2012 transparency

Is this also working for R2010b on a Linux Machine?

19 Jan 2012 Mark

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

10 Jan 2012 Sun  
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 Benjamin  
06 Oct 2011 Guillaume MARTIN

Simple, efficient : what I needed !

25 Aug 2011 Chee Syn Ang  
24 Mar 2011 Guy Rouleau

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.

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

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

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

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

Minor modif for BSD license

21 Jul 2010

- 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

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

Contact us