Call a Function in a statemachine
Mostra commenti meno recenti
I have two reference subsystems. In the first one is my statemachine. In the second reference subsystem is another subsystem and within that is my simulink function.
I want to call that function in the statemachine in an insert state. For that i wanted to use the convetion
reference_subsystem_name.subsystem_name.function_name()
unfortunatly i receive the error message: undefined function, errors occurred during parsing of ...
I'm sure that the spelling and name is correct.
In a previous version of my model I had one subsystem less so I only had to use subsystem_name.function_name() and that worked.
Thank you for your help
Risposte (1)
Poorna
il 6 Dic 2023
0 voti
Hi Svenh,
I understand that you are trying to call a Simulink function from inside your Stateflow chart. I also understand that you are wondering why putting Simulink function inside a subsystem at the same level as the chart works, while placing the grandparent subsystem of the Simulink function at the same level as the chart does not work.
The behaviour you are seeing is expected. The Simulink function you're using is a "scoped" function residing inside a virtual subsystem. A scoped function within a virtual subsystem can be called within the containing subsystem block hierarchy simply by using its name, like "function_name()". It can also be called from outside the subsystem but within the subsystem hierarchy by qualifying the function name with the subsystem block name, like "subsystem_name.function_name()".
Because the subsystem "subsystem_name" is not within the subsystem hierarchy of the chart (while "referenced_subsystem_name" is in the hierarchy, "subsystem_name" is not), you cannot use its Simulink function.
To still access the Simulink function, you can consider changing the scope of the Simulink function to "global". In this case, a simple call like "function_name()" should work across the model, as long as the Simulink Function is inside a virtual subsystem hierarchy.
To can find the option to change the function’s scope in the Block properties of the trigger port of the Simulink function block.
To know more about accessing Scoped Simulink function blocks in subsystems refer to the following documentation:
For an overview of different scopes of a Simulink function block, please refer to the following documentation:
Hope this Helps!
Best regards,
Poorna.
Categorie
Scopri di più su Simulink Functions in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




