0

I'm using Stateflow (Matlab R2016b) with a vector output signal. The usage of matlab action language is hard to understand.

  1. Set a value for whole array

Within matlab I use:

>> x = ones(1,3)
x =
     1     1     1
>> x(:) = 2
x =
     2     2     2

to set all values to a specific value. But within stateflow i get following error

Inferred size ('scalar') for data 'x' does not match specified size ('[1 3]').

So, i have to use in stateflow

x = 2*ones(1,3)

Is there any other way of easy access to all elements?

  1. Change dynamically some of the values

Within matlab I can run

x(myStartIndex:end) = 5

But within stateflow, that gives me the error

Could not determine the size of this expression.

I don't think that building for-loops within statelow is a proper coding style.

Thanks in advance.

amw
  • 452
  • 1
  • 5
  • 14
  • Is `2*ones(1,3)` such a problem? You can also use `repmat()`, e.g. `repmat(2, [1 10])` which will give you a row of 1x10 filled with the value 2. – 10a Sep 26 '17 at 11:28
  • I would like to have the code flexibel in terms of size, because the size is changing during project often. – amw Sep 26 '17 at 11:39
  • What do you mean by "the code flexible in terms of size"? Do you mean you want `x` to be flexible? Just change the size by a parameter? – 10a Sep 26 '17 at 11:42
  • Yes, you're right. I will live with that solution for question 1. But do I have to make a loop within stateflow to solve question 2? Matlab language should support matrix functions instead of self-made-loops. – amw Sep 26 '17 at 11:53
  • For question 2, it works in Matlab so somewhere in your stateflow it goes wrong. For question 1, I still don't get what you really want because I don't see how it can be easier. – 10a Sep 26 '17 at 12:01
  • For question 1: I just wanted in shorter :-) – amw Sep 26 '17 at 12:33
  • For question 2: I get the error mentioned in the question. Can't find any error. – amw Sep 26 '17 at 12:33
  • Even shorter than one short formula? :p For question, check this: https://de.mathworks.com/matlabcentral/answers/92878-why-does-embedded-matlab-fail-to-detemrine-the-size-of-my-expression-in-simulink-7-2-r2008b – 10a Sep 26 '17 at 13:42

0 Answers0