Access Data Store Data in MATLAB Function Blocks
You can use data defined in data stores in MATLAB Function blocks by defining global variables in the function code. Use data from data stores if:
You have data in a model that you want to access in multiple instances of a MATLAB Function block.
You add a MATLAB Function block to an existing model that uses data stores, and you want to avoid cluttering your model with additional inputs and outputs.
You have at least one MATLAB® function or script that you want to call in a MATLAB Function block that also must access data in a data store.
You want to scope the visibility of data to parts of the model.
MATLAB Function blocks can access data in data stores defined in either Data
Store Memory blocks or Simulink.Signal
objects. For more information,
see Local and Global Data Stores.
Choose How to Define Data Stores
How you store global data depends on the number and scope of your global variables.
How You Use Data Stores | Solution |
---|---|
In a single model that uses a small number of data store data sources. | Use Data Store Memory blocks. See Access Data in Data Store Memory Blocks by Using MATLAB Function Blocks. |
In a single model that uses a large number of data store data sources. | Use Simulink.Signal objects. See Access Data in Simulink.Signal Objects by Using MATLAB Function Blocks. |
In multiple models, including referenced models. | Use Simulink.Signal objects. See Access Data in Simulink.Signal Objects by Using MATLAB Function Blocks. |