How can I read an external file in Simulink to get some parameters in a way supported for code generation?

2 次查看(过去 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?

回答(1 个)

Manjunath Bhimalli
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
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.

类别

Help CenterFile Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by