How can I read in data of a text file with an S-Function and generate code from the model that contains this S-Function in Simulink 8.2 (R2013b)?

4 visualizaciones (últimos 30 días)
I would like to read data from a text file and use the data in my simulation. Additionally I need to generate code from that model, because I run this model on external hardware.

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 28 de Nov. de 2013
To read data from a text file, you can write your own S-Function. Generating code from the model containing an S-Function requires a TLC file.
In this case, it is best to use the Legacy Code Tool to include custom C-Code that does the low level file I/O. Legacy Code Tool can then create the necessary TLC file automatically.
Please see the attached example. After unzipping the files please run "create_sfun_readfile.m". It will automatically create the S-Function, the mex file, the TLC file and the block that can be used in the model.
Please be aware, that during the build process, the TLC file needs to be on the MATLAB path or in the code generation folder.

Más respuestas (0)

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Productos


Versión

R2013b

Community Treasure Hunt

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

Start Hunting!

Translated by