How to access existing variable with Data Store Read in Simulink?
1 次查看(过去 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!
0 个评论
回答(1 个)
Shubham
2024-9-11
编辑:Shubham
2024-9-11
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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Event Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!