Can I pass a "coder.opaque" variable from one Matlab function to another inside a StateFlow diagram?

4 次查看(过去 30 天)
Hi!
I have a StateFlow chart (C action language) that calls a Matlab function embedded on it. This Matlab function calls an external C function using coder.ceval, which returns a variable that is declared using coder.opaque.
I have another Matlab function embeeded on the same Stateflow that calls another external C function and that requires the coder.opaque variable returned by the previous Matlab function to be passed as an argument.
Is there a way that I can pass that coder.opaque variable from the first Matlab function block to the second one?
I would imagine that joining the two Matlab functions inside the same block (and adding a switch-case statement to execute one or the other) can work, but I would really like to have them in separate blocks.
My objective is to generate the code of the model. Thanks in advance!

回答(1 个)

Poorna
Poorna 2023-12-6
Hi Marcus,
I understand that you want to share the “coder.opaque” value between two different stateflow states.
You can achieve this by using Data Store Memory blocks. These blocks are capable of code generation and can be utilized across the model. Follow these steps to use Data Store Memory in your chart:
  • Add a Data Store Memory Block to your model.
  • Set the Name property to the variable name you are going to use.
  • In the Modeling tab, under Design Data, select Symbols Pane.
  • Click the Create Data icon. Edit the name of the new Data and set the type to Data Store Memory.
  • Now, you can use the Data variable as usual.
Please refer to the below documentation to know more about accessing Data Store Memory from charts.
Refer to the below documentation to learn more about Data Store Blocks.
Hope this Helps!
Best regards,
Poorna.

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by