Effacer les filtres
Effacer les filtres

How to define the variables as 'Global variables' within a Matlab Function block in Stateflow?

22 vues (au cours des 30 derniers jours)
I am trying to read some variables calculated in a Matlab Function defined in stateflow without calling them locally by the variable names and function name. A simple stateflow program is shown below.
In the stateflow chart, I have defined two Matlab functions to calculate the mean, sum and std.
These two functions are written as below.
function [meanv, sumv] = meanstats(vals)
function stdev = stdevstats(vals)
stdev = std(vals);
I modified the representation a bit as:
But, I want to access the outputs or Calculated values of the Functions without calling them in the State together with the FunctionName but just executing the function only, as below. But those output calculations should be displayed out of the state machine, and will be used in different calculations.
How can I define any variable globally in a Matlab Function that is to be accessed from anywhere in the program, because in the real program I have to define many variables within the same function?

Réponses (1)

Jesús Zambrano
Jesús Zambrano le 15 Sep 2021
A way to solve this question could be by:
First, in the chart properties, set the "Export chart level functions" and "Treat exported functions as globally visible":
Then, use two Function Caller blocks, and call the functions as they were defined inside the chart:
Hope it helps!


En savoir plus sur Simulink Functions dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by