How can I have Matlab Simulink autocode program read data from an external file?
Ältere Kommentare anzeigen
I have a Simulink model that contains calculations that I want to have it perform on different external data files. I want to generate C-code autocode from the model that I can compile into an EXE application file. I would like the application to prompt me for the input data file to read and an output file to write the results. I'm having difficulty figuring out what I need to put in the model for the I/O interface and how to type cast all the I/O variables. I would really like some kind of an example for doing simple external file I/O just to get me started but i haven't been able to find anything in my searches yet. Any hints or suggestions would be appreciated - thank you!
2 Kommentare
Piyush Kumar
am 13 Mär. 2025
@Glen Tallarek, please check the 'From File' block, which is used to load data from a MAT file into a Simulink model, and the 'To File' block, which is used to write data to a file.
Glen Tallarek
am 13 Mär. 2025
Bearbeitet: Glen Tallarek
am 13 Mär. 2025
Antworten (1)
Hi Glen,
In order to promt for user input in your compiled application, you will need to incorporate custom C/C++ code in the generated code since the MATLAB 'input' function is not supported for code generation.
Once you take the filename input using your C/C++ code, you can use one of the the MATLAB's various functions to read and write the data to text files(CSV, TXT, M). To call these MATLAB functions from C/C++ code, you can use MATLAB External Interfaces.
This is one of the approaches you can follow.
1 Kommentar
Glen Tallarek
am 10 Apr. 2025
Kategorien
Mehr zu Simulink Coder finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!