MATLAB Function block containing a locally defined "struct" outputs an error that the struct is not defined

7 ビュー (過去 30 日間)
I have a MATLAB Function block (MLFB) that contains the below script:
simParameters = []; % Clear the simParameters variable
simParameters.NumFramesSim = 30; % Simulation time in terms of number of 10 ms frames
simParameters.NumUEs = 4;
simParameters.UEDistance = [100; 400; 1500; 1000];
The code is simply creating a "struct" "simParameters" that has a few "double" elements. The above script would execute just fine in a regular MATLAB script. But, in the MLFB, when I run the model, I get the below error message:
Error:Attempt to extract field 'NumFramesSim' from 'double'.
Function 'Function-Call Subsystem/MATLAB Function' (#24.156.169), line 8, column 1:
"simParameters"
Launch diagnostic report.
Error:Attempt to extract field 'NumUEs' from 'double'.
Why does this script execute nominally in a regular MATLAB script but throws the above errors in MLFB?

採用された回答

MathWorks Support Team
MathWorks Support Team 2020 年 12 月 10 日
In a MATLAB Function Block, compiled code from MATLAB is being "generated" to be included in Simulink. So, to define and declare a "struct", just like "simParameters", you would need to follow a different workflow and syntax than the one in the example code you are using.
In the below link, there is an overview of how structures should be defined in MATLAB Function Blocks:https://www.mathworks.com/help/simulink/ug/create-structures-in-matlab-function-blocks.html
For example, if you are only defining "simParameters" to be a local struct and not an output of your block, maybe you can follow the recommendation listed in the below link:https://www.mathworks.com/help/simulink/ug/defining-scalar-structures-for-code-generation.html

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEvent Functions についてさらに検索

タグ

タグが未入力です。

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by