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

9 次查看(过去 30 天)
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!

回答(1 个)

Shubham
Shubham 2024-9-11,16:52
编辑:Shubham 2024-9-11,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!

类别

Help CenterFile Exchange 中查找有关 Event Functions 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by