![For_Illustration.JPG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/233038/For_Illustration.jpeg)
How can I read an external file in Simulink to get some parameters in a way supported for code generation?
4 次查看(过去 30 天)
显示 更早的评论
I have a Simulink model that I use to generate standalone code for embedded use (GRT target).
I need some parameters to perform calculations inside a subsystem. I do not want to provide them through input ports, but with an external file (.CSV, .TXT or other) as this subsystem shall have the same ports of other blocks that do not need those specific parameters.
The options I found are:
- "From File" block accepts only .MAT files and for code generation it requires timeseries signals (unconvenient for my goal if dealing with lots of parameters);
- "From Spreadsheet" block accepts excel and .CSV files but does not support generating code that involves building ERT or GRT targets;
- "Matlab Function" block with fopen command is supported for code generation. A writing procedure of an external file is successfully supported for standalone code generation. However I cannot find a compatible way to read an external file: with fread it is possible to read data but as I need fscanf, sscanf, textscan, xlsread, regexp or fgetl, they are not supported.
Is there a good way to resolve the issue?
0 个评论
回答(1 个)
Manjunath Bhimalli
2019-8-7
From your problem statement it shows that you have a model whic looks below and need to add few parameters specific to only for SubSytsem_A/B and do not want to add them as new inputs.
![For_Illustration.JPG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/233038/For_Illustration.jpeg)
Solution: If this is the case make them as configurable and define thier structure in new xyz.m file and include as preload function, read/use them via constant blocks in your logic(SubSytsem_A/B) wherver required.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!