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

67 vues (au cours des 30 derniers jours)
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 commentaire
Victor Maciel
Victor Maciel le 29 Avr 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)];

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 26 Avr 2021
u = d_u + u_old;
Before that assign
u = zeros(m, 1);
  2 commentaires
Victor Maciel
Victor Maciel le 29 Avr 2021
Thanks for answering. I got another solution, but I think that yours works.
esmail mobasher
esmail mobasher le 3 Juil 2023
hi victor, how did you solve?

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by