Clear Filters
Clear Filters

How to access existing variable with Data Store Read in Simulink?

9 views (last 30 days)
I use a third party c library with my Simulnk model as Custom Code. I'd like to access a global variable exported in this library with a Data Store Read block from the Simulink model. However I don't know how to tell the Data Store Memory block that it is an already existing variable. It always exports the definition no matter what, and also initializes the variable with de default values. How can it be achieved? Thanks!

Answers (1)

Shubham
Shubham on 11 Sep 2024 at 16:52
Edited: Shubham on 11 Sep 2024 at 16:54
Hey Csaba,
I understand that you want to use external C/C++ code to import certain variables to be later used by Data Store Memory block.
In order to use the global variables defined in the external code, the recommended practice is to use a Stateflow chart in order to call your function and to access the variables. You would need to write C/C++ code in the chart so that during simulation, the model reads and writes to the variables. These global variables can be converted into MATLAB variables and then used to initialize Data Store Memory block.
Once you can access the variables defined externally, you can use them to modify the Data Store Memory block.
For more information upon accessing the variables from an external C/C++ code into your Simulink model, refer to the "Import External Code into Model" section of the following documentation: https://www.mathworks.com/help/rtw/ug/generate-code-for-interfacing-data-with-external-code.html#:~:text=Integration%20Workflow.-,Import%20External%20Code%20into%20Model,-To%20exchange%20data
I hope this helps!

Categories

Find more on Event Functions in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!