0

I want to shift an array within stateflow by one element.

In matlab, I would use circshift or this code:

>> x = [1:5]
x =
     1     2     3     4     5
>> x(2:end) = x(1:end-1)
x =
     1     1     2     3     4
>> x(1) = 0 % New Value
x =
     0     1     2     3     4

How can I implement this in stateflow action language. Embedded matlab-function is not possible because of realtime-target.

I tried this:

{x[2:end] = x[1:end-1];
x[1] = 0;}

but thats a syntax error. For loop should be possible as well, but thats strange to me in matlab :-)

Thanks in advance

Mohsen Nosratinia
  • 9,844
  • 1
  • 27
  • 52
amw
  • 452
  • 1
  • 5
  • 14
  • 2
    A MATLAB Function (what you call Embedded MATLAB) is possible for a real-time target. In fact, that's precisely what they are designed for. – am304 Apr 24 '15 at 08:12
  • 2
    @am304, agreed. You could also consider using [MATLAB as the action language](http://www.mathworks.com/help/stateflow/ug/modify-the-action-language-for-a-chart.html) for your Stateflow chart since [`circshift` supports code generation](http://www.mathworks.com/help/coder/ug/functions-supported-for-code-generation--alphabetical-list.html) – Ryan Livingston Apr 24 '15 at 10:32

1 Answers1

0

Both answers in comments helped a lot: Matlab Function works also with my target and circshift works fine.

amw
  • 452
  • 1
  • 5
  • 14