File Exchange

image thumbnail


version (36.9 KB) by Giampiero Campa
Saves data to a file at the end of the simulation


Updated 23 Oct 2007

View License

This block is similar to the "To File" original simulink block, except for the following points:

1) It does not access the file system during the simulation, in fact it collects data in memory and saves them to file only when the simulation is over. This is important for real time systems, where normally access to the file system by processes running in real time has to be avoided.

2) It can save any type of data instead of just doubles.

3) It has a lot of flexibility in saving the data, different format and precisons can be selected form the block mask.

4) When using the %d, %f or %e options, the file is an ASCII file that can be opened with any text editor as well as easily loaded into matlab or excel.

This code is derived from an original s-function written by G.Campa and S.Gururajan for simulink schemes running in real time under RTAI-Linux.

Cite As

Giampiero Campa (2019). savedata (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (1)

Rocco Dell'Aquila

Great Job !!!


Recompiled the s-function with matlab 7.1 so that everything works fine with newer versions requiring the .mexw32 extension. The .dll files is retained to the benefit users working with versions prior to 7.1, other users may delete it.

1) Minor fixes to the mask and model.
2) mdlInitializeSizes now uses "DTypeId" instead of "int", so it's more formally correct and robust to possible future changes by TMW in the way data types are handled.

MATLAB Release Compatibility
Created with R11.1
Compatible with any release
Platform Compatibility
Windows macOS Linux