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

3 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 28 Nov 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.

Più risposte (0)

Categorie

Scopri di più su Simulink Coder in Help Center e File Exchange

Prodotti


Release

R2013b

Community Treasure Hunt

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

Start Hunting!

Translated by