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

72 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 2 Sep. 2021
Bearbeitet: MathWorks Support Team am 27 Sep. 2021
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);

Weitere Antworten (0)

Kategorien

Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by