Stateflow get dimension of variable

3 ビュー (過去 30 日間)
Roger Innes
Roger Innes 2024 年 2 月 15 日
コメント済み: Fangjun Jiang 2024 年 2 月 23 日
I would like to get the dimension of an input/parameter to a stateflow model?
C code would be something like this.
Vartype Var[MaxArraySize];
size_t MaxArraySize = sizeof(Var) / sizeof(Vartype);

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2024 年 2 月 15 日
If action language is MATLAB, you can use size(input), or size(input,1), size(input,2)
  2 件のコメント
Roger Innes
Roger Innes 2024 年 2 月 23 日
The issue was I was indexing the matix on the same line. size( input )(x) which is invalid matlab syntax. Using size( input, x) where x = 1 I got the length of the 1 by 3 matrix as 3.
The error I was getting was.
Parse error: ()-indexing must appear last in an index expression. State 'Test' "size( input )"
Which made it hard to understand what I was doing wrong. Which lead me to concluded the "size" command was invalid but it works correctly in stateflow.
Fangjun Jiang
Fangjun Jiang 2024 年 2 月 23 日
size( input )(x) is not valid in MATLAB.
"Using size( input, x) where x = 1 I got the length of the 1 by 3 matrix as 3"
If not specified, a 1x3 or 3x1 vector in Simulink shows size as 3 (at least in Simulink diagram signal line). If you specify the dimension of "input" as 1x3, I think size(input,1) will return 1.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by