Error in simulink, the upper bound is not specified

1 次查看(过去 30 天)
Hello everyone,
I am trying to build a matrix with a matlab function in Simulink. However, I always get some error message and already tried to fix it with:
coder.varsize('y1', [1,L], [0 1]);
The error message is the following:
This is the matlab function
function [y1, y2, y3, L] = fcn(u, x, acc_y, acc_z,L,k)
coder.varsize('y1', [1,L], [0 1]);
coder.varsize('y2', [1,L], [0 1]);
coder.varsize('y3', [1,L], [0 1]);
if u == 0
y1 = zeros(L,1);
y2 = zeros(L,1);
y3 = zeros(L,1);
elseif u < 1
r = randi([1 k(1)-L],1,1);
y1 = x(1,r:r+L);
y2 = acc_y(r:r+L,1);
y3 = acc_z(r:r+L,1);
elseif u < 5
r = randi([1 k(2)-L],1,1);
y1 = x(r:r+L,2);
y2 = acc_y(r:r+L,2);
y3 = acc_z(r:r+L,2);
elseif u < 10
r = randi([1 k(3)-L],1,1);
y1 = x(r:r+L,3);
y2 = acc_y(r:r+L,3);
y3 = acc_z(r:r+L,3);
elseif u < 15
r = randi([1 k(4)-L],1,1);
y1 = x(r:r+L,4);
y2 = acc_y(r:r+L,4);
y3 = acc_z(r:r+L,4);
elseif u < 20
r = randi([1 k(5)-L],1,1);
y1 = x(r:r+L,5);
y2 = acc_y(r:r+L,5);
y3 = acc_z(r:r+L,5);
elseif u < 25
r = randi([1 k(6)-L],1,1);
y1 = x(r:r+L,6);
y2 = acc_y(r:r+L,6);
y3 = acc_z(r:r+L,6);
elseif u < 30
r = randi([1 k(7)-L],1,1);
y1 = x(r:r+L,7);
y2 = acc_y(r:r+L,7);
y3 = acc_z(r:r+L,7);
elseif u < 35
r = randi([1 k(8)-L],1,1);
y1 = x(r:r+L,8);
y2 = acc_y(r:r+L,8);
y3 = acc_z(r:r+L,8);
elseif u < 40
r = randi([1 k(9)-L],1,1);
y1 = x(r:r+L,9);
y2 = acc_y(r:r+L,9);
y3 = acc_z(r:r+L,9);
elseif u < 45
r = randi([1 k(10)-L],1,1);
y1 = x(10,r:r+L);
y2 = acc_y(r:r+L,10);
y3 = acc_z(r:r+L,10);
elseif u < 50
r = randi([1 k(11)-L],1,1);
y1 = x(r:r+L,11);
y2 = acc_y(r:r+L,11);
y3 = acc_z(r:r+L,11);
elseif u < 55
r = randi([1 k(12)-L],1,1);
y1 = x(r:r+L,12);
y2 = acc_y(r:r+L,12);
y3 = acc_z(r:r+L,12);
elseif u < 60
r = randi([1 k(13)-L],1,1);
y1 = x(13,r:r+L);
y2 = acc_y(r:r+L,13);
y3 = acc_z(r:r+L,13);
elseif u < 65
r = randi([1 k(14)-L],1,1);
y1 = x(r:r+L,14);
y2 = acc_y(r:r+L,14);
y3 = acc_z(r:r+L,14);
elseif u < 70
r = randi([1 k(15)-L],1,1);
y1 = x(r:r+L,15);
y2 = acc_y(r:r+L,15);
y3 = acc_z(r:r+L,15);
elseif u < 75
r = randi([1 k(16)-L],1,1);
y1 = x(r:r+L,16);
y2 = acc_y(r:r+L,16);
y3 = acc_z(r:r+L,16);
else
r = randi([1 k(17)-L],1,1);
y1 = x(r:r+L,17);
y2 = acc_y(r:r+L,17);
y3 = acc_z(r:r+L,17);
end
L = L;
The setting of y1 is the following:

回答(1 个)

Chaitanya Mallela
Chaitanya Mallela 2020-12-24
you must specify a numerical upperbound in the size column in Ports and Data Manager to make Simulink realize a variable sized array. In this case you may declare size as [1,L].
Refer the documentation that demonstrates variable size declarations

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by