- When the model is run in Simulink, it will read "A = 2", increment by 1, and save the updated "A" to the MAT file. Running the model afterward will continue to increment A by 1.
- Whereas, when the model is compiled, the value of "A = 2" is hard-coded, so the "From File" block reads the hard-coded value rather than reading from the file. Running the model afterward will continue to use hard-coded "A = 2" and increment it by 1.
"From File" block does not update MAT files after compiling my model with Simulink Compiler
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 10 de Feb. de 2021
Editada: MathWorks Support Team
el 4 de Feb. de 2025
I have a Simulink model that loads data from MAT files using 'From File' block, updates the data, and saves it to the same MAT files at the end of the simulation.
- When the model is run in Simulink, there are no issues and the data in the MAT files is updated as expected.
- When I run the compiled model, the MAT files are not updated. Rather at the end of the simulation, they contain the same data that was there when the model was being compiled.
Respuesta aceptada
MathWorks Support Team
el 4 de Feb. de 2025
Editada: MathWorks Support Team
el 4 de Feb. de 2025
This behavior is expected. When code is generated for the 'From file' block, the data in the target file is inlined to optimize it, i.e., hard-coded. Thus, any changes made to the target file after code generation are not honored by the compiled model.
For example, suppose you have a MAT-file containing a variable "A" with a value of 2, and a Simulink model that adds 1 to "A" and updates the MAT file.
For more limitations, please refer to the following documentation page by executing this command in the MATLAB R2020a command window:
>> web(fullfile(docroot, 'simulink/slref/fromfile.html?searchHighlight=fromfile'))
If you wish to change the data input to a compiled model after every run, please use an 'Import Block'. To view the relevant documentation, execute this command in the MATLAB R2020b command window:
>> web(fullfile(docroot, 'simulink/slref/inport.html'))
and supply the MAT-file as a root-level input. For more information, execute this command:
>> web(fullfile(docroot, 'simulink/ug/load-data-to-root-level-input-ports-1.html'))
This way, the code is compiled in such a way that the changing external data is honored.
Please follow the link below to search for the required information regarding the current release:
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Prepare Model Inputs and Outputs en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!