How to define the variables as 'Global variables' within a Matlab Function block in Stateflow?
13 次查看(过去 30 天)
显示 更早的评论
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)
meanv=mean(vals);
sumv=sum(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?
0 个评论
回答(1 个)
Jesús Zambrano
2021-9-15
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!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!