How can i maintain different variable(global) for multiple instances of same block.

2 次查看(过去 30 天)
I have generated a library.
Integrated external c function using s-function builder.
Different instances of the custom block operates on a single global variable. My requirement needs to maintain separate global variable for multiple instances.
How can i get that to work?
Using R2020b

回答(1 个)

Rishav
Rishav 2024-2-19
Hi Anamika,
You can use Simulink's S-Function API to manage instance-specific data. Please follow the below mentioned steps to achieve the same:
  1. Define a structure to hold the instance-specific data for each block instance. This structure will include the global variable and any other relevant information.
  2. Use the S-Function's 'mdlInitializeSizes' function to allocate memory for the instance-specific data structure for each block instance.
  3. Use the S-Function's 'mdlOutputs' or 'mdlUpdate' functions to access and manipulate the instance-specific data as needed.
You can also refer to the below mentioned documentations on:
  1. mdlInitializeSizes - https://www.mathworks.com/help/releases/R2020b/simulink/sfg/mdlinitializesizes.html
  2. mdlOutputs - https://www.mathworks.com/help/releases/R2020b/simulink/sfg/mdloutputs.html
  3. mdlTerminate - https://www.mathworks.com/help/releases/R2020b/simulink/sfg/mdlterminate.html

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by