How do I resolve an error about variable sized data in my MATLAB Function block?

조회 수: 16 (최근 30일)
I am trying to implement a MATLAB Function block with variable-sized output, but I get the following error when I try to update my model:
Output 'y' has variable size but the upper bound is not specified;
explicit upper bound must be provided.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2021년 9월 2일
편집: MathWorks Support Team 2021년 9월 27일
If the size of the variable can change during run-time:
You need to set up the sizes in the Data Editor for the MATLAB Function Block as per:
In the editor for your MATLAB Function Block code, click "Edit Data" to open the Ports and Data Manager, and check the variable-size box for y and give, for example, [513 1] as the upper bound/size. Doing this alerts Simulink to the fact that the data should be variable-size.
If the size of the variable does not change during run-time:
In case you do not want to have variable-size signals in your model, and the size of your data does not change during run-time and is known at compile-time, consider the following approach:
Define a parameter for your MATLAB Function Block by clicking Add > Data in the Ports and Data Manager. Select 'Parameter' as scope, and make sure that the 'Tunable' box is not checked.
You can use this constant parameter now to define the variable sizes at compile-time, by creating a variable of the same name in the MATLAB or model workspace or in the workspace of a masked subsystem containing this MATLAB Function Block. Then, you will be able to use code such as the following in your MATLAB Function block:
>> out = zeros(small,1);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Event Functions에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by