필터 지우기
필터 지우기

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

조회 수: 81 (최근 30일)
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
Victor Maciel
Victor Maciel 2021년 4월 29일
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)];

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2021년 4월 26일
u = d_u + u_old;
Before that assign
u = zeros(m, 1);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Attributes and Indexing에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by