Simulink function block array element operation with a fixed size

How can I achieve a array element opertion within the function block? The output of the function is sent to a integrator. Therefore, the output has a defined size.

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 2 日

0 投票

Change the code inside MATLAB function block to this
dy_dt = zeros(5,1);
dy_dt(1:3,:) = vars.g*u.*0.1.*y(1:3,:);
dy_dt(4:5,:) = vars.lambda*u.*0.1.*y(4:5,:);
Note that the first line is necessary for telling the compiler about the size of output dy_dt. Also, you cannot use zeros(var.size,1) since the compiler still cannot decide the value at compile time.

4 件のコメント

Jiwei Yao
Jiwei Yao 2020 年 11 月 2 日
Thanks!! But is there any way that I can change the dy_dt size without going into the function block?
Ameer Hamza
Ameer Hamza 2020 年 11 月 2 日
See the attached files. Note that, inside the MATLAB function block, I have defined a non-tunable parameter with the name of mySize (variable with this name also need to be defined in base workspace). You can check its properties by clicking the "Edit Data" button on the toolbar. This button will only appear when you open the MATLAB function block.
Jiwei Yao
Jiwei Yao 2020 年 11 月 2 日
Thank you so much!!!
Ameer Hamza
Ameer Hamza 2020 年 11 月 2 日
I am glad to be of help!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSimulink Functions についてさらに検索

製品

質問済み:

2020 年 11 月 2 日

コメント済み:

2020 年 11 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by