I wrote a Matlab function in Simulink. The compilation process detects that u data is a variable size matrix, but it isn't on my case.
The code is showed below. The error is:
Data 'u' is inferred as a variable size matrix, while its properties in the Model Explorer specify its size as inherited or fixed. Please check the 'Variable Size' check box and specify the upper bounds in the size field. But when I check the 'Variable Size' option, other problems emerge, because all of my signals presents fixed size.
function u = buffer(d_uf, arrival_time)
m = 1;
Nc = 36;
persistent index u_old d_uf_ready time_old
if isempty(u_old)
u_old = zeros(m,1);
end
if isempty(d_uf_ready)
d_uf_ready = zeros(Nc*m,1);
end
if isempty(index)
index = 1;
end
if isempty(time_old)
time_old = 0;
end
if arrival_time < time_old
d_u = d_uf_ready(index:index+m-1);
index = index + m;
else
d_u = d_uf(1:m);
index = 1 + m;
d_uf_ready = d_uf;
end
u = d_u + u_old;
u_old = u;
end