Why do I get an error using global variables in my MATLAB Function block?

16 Ansichten (letzte 30 Tage)
Why do I get the below error upon using global variables in my MATLAB Function block?
Global declaration not resolved to Data Store Memory using global variables in my MATLAB Function block

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 5 Sep. 2025 um 0:00
Bearbeitet: MathWorks Support Team am 24 Sep. 2025 um 17:45
The Diagnostic Viewer may say something like "Global declaration not resolved to a Data Store Memory block registered via the Ports and Data Manager.", or "Global declaration not resolved to a Data Store Memory block registered with the symbols pane".
In MATLAB Functions in Simulink, global declarations are not mapped to the MATLAB global workspace. To use global data in your MATLAB Function block, or in any code that this block calls, you must:
Step 1: Declare a global variable in your MATLAB Function block script, or in any code that is called by the MATLAB Function block, 
Step 2: Initialize a variable with the same name with scope "Data Store Memory" within the symbols pane for that MATLAB Function block.
Step 3: Register a Data Store Memory block or Simulink.Signal object associated with this variable.
For Step 3, whether you choose a Data Store Memory block or a Simulink.Signal depends on whether you want to use a large number of Data Stores and whether you need to access the data across multiple models. For more information, refer to the 
.
That page also provides links to the exact steps that you need to take to carry out both Step 1 and Step 2 above for each application. For example: Access Data in Data Store Memory Blocks by Using MATLAB Function Blocks - MATLAB & Simulink
If you are using the Data Store Memory block approach, please note the following:
  • In the Ports and Data Manager, you may need to manually create the data entry and change the name to match the Data Store Memory block, and set the scope to Data Store Memory.
  • You will need to specify Dimensions, Signal type (real/complex), and Data type (e.g. double) for the variable in the corresponding Data Store Memory block. 
  • The initial value will be determined by the Initial value setting given in the Data Store Memory block. Variables of the same name in for example the Base Workspace are ignored. 

Weitere Antworten (0)

Kategorien

Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by