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일
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

Thanks!! But is there any way that I can change the dy_dt size without going into the function block?
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.
Thank you so much!!!
I am glad to be of help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink 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