MATLAB Function block containing a locally defined "struct" outputs an error that the struct is not defined
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 10 Déc 2020
Réponse apportée : MathWorks Support Team
le 11 Fév 2021
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?
Réponse acceptée
MathWorks Support Team
le 10 Déc 2020
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Event Functions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!