How can I create an array in Stateflow in the form Arr= [x y z]?
14 views (last 30 days)
Show older comments
I use normal stateflow chart (not Chart(MATLAB))in Simulink R2012b.
I want to create an array of ten elements in Stateflow of the form:
P=[P1 P2 P3 P4 P5 P6 P7 P8 P9 P10].
Each element of the P-array is read in as an input from Simulink and can change in value during the simulation. P itself is an output to Simulink that I have set up to have a size of 10.
I have tried the method above, tried
P={P1 P2 P3 P4 P5 P6 P7 P8 P9 P10} and
P=(P1 P2 P3 P4 P5 P6 P7 P8 P9 P10)
but to no avail.
I don't want to do P[0]=P1;P[1]=P2... as it will be too long for me and besides, it seems to output my result as a scalar and not a 10x1 vector when I do so.
I have also tried to use the ml function such that P is defined as
P=ml('[P1 P2 P3 P4 P5 P6 P7 P8 P9 P10]')
with the following pre-definitions: ml.P1=P1, ml.P2=P2.... This too returns an error: 'Eval of MATLAB expression '[P1 P2 P3 P4 P5 P6 P7 P8 P9 P10]' in base workspace didn't return anything...'
I know this is straightforward in Matlab but I don't understand why it is so difficult in Stateflow.
Anyone who has addressed a similar challenge before should pls help. Any help will be greatly appreciated.
Thanks.
0 Comments
Answers (2)
Azzi Abdelmalek
on 13 Jan 2013
Edited: Azzi Abdelmalek
on 15 Jan 2013
You can use
P=[P1 P2 P3 P4 P5 P6 P7 P8 P9 P10].
% P=(P1 P2 P3 P4 P5 P6 P7 P8 P9 P10) is not valid
Or you can use a MUX block in simulink, you will pass through it P1,P2,... then your Stateflow chart will have one input P with size (1,10). If you need P3 in your Stateflow chart, just use P[2].
3 Comments
Azzi Abdelmalek
on 13 Jan 2013
Edited: Azzi Abdelmalek
on 13 Jan 2013
In your simulink model use a MUX block to have one signal P_in with size 10. Then your stateflow chart will have one input with size 10. In you chart click on your model explorer, set the size of your input P_in and output P_out to 10. If you want to use P1, just use P_in[0], for P2, it's P_in[1], and so on.
To output your signal just use
P_out=P_in
Guy Rouleau
on 14 Jan 2013
In R2012b, the MATLAB Chart was introduce. In this release your initial attempt should work.
0 Comments
See Also
Categories
Find more on Event Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!