Why is MATLAB/Simulink function call creating duplicated / cloned parameters?
Mostrar comentarios más antiguos
I have a MATLAB/Simulink software which is converted to C code, to be applied as an embedded application.
Inside this Simulink model I have a few stateflow with function call charts. These subsystems refer to some base workspace parameters to do their calculations, as follows:

Whenever I try to simulate this model, stimulating the inputs and reading the outputs, I get the following 'glitch' - the workspace defined variable 'multiplies', and the model simulation crashes because these new parameters have no defined values:

If I try to run the model again, more clones are created (4, 5 ,6 ...).
Do anyone has any clue on this?
Thanks!
Respuestas (1)
Karan Singh
el 29 de Sept. de 2023
0 votos
Hi Matheus,
From what I understand, a MATLAB-Simulink model has been converted to C code for deployment as an embedded application and within this Simulink model, there are Stateflow charts that make use of parameters from the base workspace to perform calculations. While during the simulation of the model, when providing inputs and reading outputs, leads to creation of multiple clones and errors.
The issue you're facing seems to be related to the usage of base workspace parameters in your Simulink model, specifically within the Stateflow charts. When the model is converted to C code and deployed as an embedded application, the base workspace is not available, leading to undefined values for the parameters.
To address this issue, you can consider the following approaches:
- Local Parameterization: Instead of relying on base workspace parameters, you can parameterize the Stateflow charts locally within the charts themselves. By doing so, the parameters will be accessible within the Stateflow charts even without the base workspace.
- Model Workspace: Simulink provides a model workspace that can be used to define model-specific parameters. These parameters can be accessed by the Stateflow charts and other components within the model. To define parameters in the model workspace, go to the Simulink Editor, click on the "Modeling" tab, and select "Model Settings." In the "Model Settings" dialog, navigate to the "Model Properties" tab and click on "Model Workspace" to define the necessary parameters.
- Input Ports: Instead of relying on base workspace parameters, you can pass the required parameters as input signals to the Stateflow charts. By connecting the input ports of the charts to the corresponding parameters, you ensure that the necessary values are provided during simulation or deployment.
Attached below are some documentation links that you may find helpful:
- Simulink Documentation (mathworks.com)
- Stateflow Documentation (mathworks.com)
- Model Workspaces - MATLAB & Simulink (mathworks.com)
Hope this helps!
Karan Singh Khati
1 comentario
Matheus Sozza
el 29 de Sept. de 2023
Categorías
Más información sobre Simulink Functions en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!