Define global variables for MATLAB function usage within Simulink for Embedded Code
9 views (last 30 days)
Show older comments
Hello,
I'm trying to create a global variable in my Simulink model, that will be visible within all MATLAB function blocks. I used the Simulink.Signal class with all properties defined. Inside the function, the 'global varName' is included, as well as variable is defined as Data Store Memory. The following error occurs:
Found unsupported global datainitialization class dor global variable 'varName'
Code generation does not supportimporting handle classes from MATLAB
As Simulink.Signal is handle class, I assume i can't use it to generate code from model to run in on HW.
Is there a way to define one, let's say Data Dictionary, to store all variables that I will use within all submodel of my main model and define which are global? I do not want to define them every time I create a new submodel and i want to enable visibility of variables within the MATLAB functions, without putting them as input every time (what I normally practise).
I also tried to use enum class, and that approach is visible in MATLAB functions, but sometimes there is a need to define two parameters of the same value (I would like to use structures instead of enums). Next problem occurs while using same 'Multiplier' field in 2 enums with different names. Simulink cannot generate code while using this approach.
classdef CurrentProtectionThresholds < int16
enumeration
Multiplier (100)
DischargeWarningThr (-1000)
DischargeErrorThr (-1200)
ChargeWarningThr (250)
ChargeErrorThr (300)
ImmunityLow (-50)
ImmunityHigh (50)
end
end
Thanks for help.
0 Comments
Answers (1)
See Also
Categories
Find more on Event Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!