carrayssimulinkstateflow

Stateflow chart and C Action Language. Set array values for give in output a vector in single step


i'm sorry, maybe is a stupid question, but i have issue to set my array variable in a stateflow chart by using C Action Language.

Usually in c language i can put in my static array all the values with " A[]={1,3,2}; " , but in stateflow chart, with C ActionLanguage how i can it? (in matlab language work, but i need in C) I've defined my variable with output scope (becouse it is), setted the size as 3 (i want an array of 3 elements), set First index as "0" and type int8.

If a want in output the array "1,2,3" i write " gates=[1,2,3]; " , i've tried also "gates=[1 2 3]", etc, but i receive syntax error. What are my errors? i've read in this link: https://it.mathworks.com/help/stateflow/ug/operations-for-vectors-and-matrices.html

Assign Values to All Elements of a Matrix In charts that use MATLAB as the action language, you can use a single action to specify all of the elements of a vector or matrix. For example, this action assigns each element of the 2-by-3 matrix A to a different value: A = [1 2 3; 4 5 6]; In charts that use C as the action language, you can use scalar expansion to set all of the elements of a vector or matrix to the same value. Scalar expansion converts scalar data to match the dimensions of vector or matrix data. For example, this action sets all of the elements of the matrix A to 10 A=10;

but not explain how set different values in all the array, and also i need that the output from the stateflow chart is in a single step :(. in the image there is a step with a syntax error. Someone can explain me how i can solve? Stateflow chart screenshot

thankyou!


Solution

  • Well, there are 2 ways I would do it:

    1. Define the values for ex: g1 = [1 0 0]; g0 = [0,0,0] in MATLAB workspace. And then in your stateflow use the values like gates = ml.g1; This works with C action language.(attached image gives a preview of this method) enter image description here
    2. Implement a for loop(maybe a graphical function or a MATLAB function) inside your chart, which is used to assign values to your output array.

    Of the two, I think the first method is easier to deal with, if the no of values the variable 'gates' takes is limited. Else, go for method 2.