How to define the variables as 'Global variables' within a Matlab Function block in Stateflow?
11 views (last 30 days)
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?
Jesús Zambrano on 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!