How can I have Matlab Simulink autocode program read data from an external file?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Piyush Kumar
il 13 Mar 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.
Risposte (1)
Suman
il 8 Apr 2025
Modificato: Suman
il 8 Apr 2025
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.
Vedere anche
Categorie
Scopri di più su Simulink Coder in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!