How I can solve the error "Data ... inferred as a variable size matrix" in Simulink?
Show older comments
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 Comment
Victor Maciel
on 29 Apr 2021
Accepted Answer
More Answers (0)
Categories
Find more on Model Verification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!