Borrar filtros
Borrar filtros

How I can solve the error "Data ... inferred as a variable size matrix" in Simulink?

46 visualizaciones (últimos 30 días)
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)
% ------------------------------------------------------------------------
% Parameters
m = 1;
Nc = 36;
% ------------------------------------------------------------------------
persistent index u_old d_uf_ready time_old
% Initialization of persistent variables
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
% Condition to use the buffer
if arrival_time < time_old
d_u = d_uf_ready(index:index+m-1);
index = index + m; % Move the index to the next block position
else % Update the buffer and use the most recent available data
d_u = d_uf(1:m);
index = 1 + m; % Restart the index counter
d_uf_ready = d_uf; % Storing to the next time sample
end
% Obtaining control signal
u = d_u + u_old;
% Storing to the next time sample
u_old = u;
end
  1 comentario
Victor Maciel
Victor Maciel el 29 de Abr. de 2021
I got a solution. The problem is on this code:
d_u = d_uf_ready(index:index+m-1);
index = index + m; % Move the index to the next block position
For some reason, Matlab understands that d_u maybe present a variable size. But it doesn't true, because the size is a fixed value m. My solution is:
d_u = d_uf_ready(1:m);
% Moving the block of available data to the next block position
dummy = d_uf_ready(m+1:end);
d_u = [dummy; zeros(m,1)];

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 26 de Abr. de 2021
u = d_u + u_old;
Before that assign
u = zeros(m, 1);

Más respuestas (0)

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by