Implementation of structures defined as a parameter of (embedded) matlab function in Simulink for code generation applications
1 回表示 (過去 30 日間)
古いコメントを表示
I know that Simulink structures (i.e., bus type objects aka non-virtual bus signals) are expensive to use in a time-critical application. Also, structures cannot be passed as inputs/outputs to/from matlab functions unless they are defined as non-virtual.
1. So, I was wondering about parameter type structures that are used inside matlab function and treated as constants to increase readability of the code? Are they modeled exactly same as non-virtual bus signals with code generation?
2. Is there a recommended size limit for a structs of this type? (e.g., in C#, it is not recommended to use structs > 16 bytes)
0 件のコメント
回答 (2 件)
Mark McBroom
2018 年 4 月 7 日
Simulink NonVirtual Buses can be used for both signals and parameters. You are correct that when used for signals, there can sometimes be unnecessary data copies, but for parameters there is no such issue. When Simulink Parameters are defined to be of type Simulink.Bus, Emdedded Coder will create an equivalent C structure in the generated code.
MATLAB function blocks fully support parameter type structures. If you define and use the structure only in the MATLAB function block, the resulting generated code will not product a C structure. If you desire to have a C structure, you will need to create a SImulink.Parameter and Simulink.Bus as described above in the MATLAB workspace and then pass this into the ML Fcn block. I am not aware of any sort of size limit for structures in MATLAB Fcn blocks.
Mark McBroom
2018 年 4 月 8 日
the elements of the struct will be treated as individual variables in the generated code. Scalar variables will be inlined.
You can use structures with coder.load also. The benefit of coder.load is that you don't have to declare the parameter values in the body of the MATLAB Fcn block, but rather in an external file. This is useful if you expect the values of the parameters to change. If the values are fixed, then it is easier to simply define the parameter values in the ML Fcn block.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Multicore Processor Targets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!